|
@@ -6,14 +6,15 @@ interface
|
|
|
|
|
|
uses
|
|
|
Classes, SysUtils, toolsunit,
|
|
|
- db,
|
|
|
- sqldb, ibconnection, mysql40conn, mysql41conn, mysql50conn, mysql51conn, pqconnection,odbcconn,oracleconnection,sqlite3conn;
|
|
|
+ db, sqldb,
|
|
|
+ mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn,
|
|
|
+ ibconnection, pqconnection, odbcconn, oracleconnection, sqlite3conn, mssqlconn;
|
|
|
|
|
|
-type TSQLDBTypes = (mysql40,mysql41,mysql50,mysql51,postgresql,interbase,odbc,oracle,sqlite3);
|
|
|
+type TSQLDBTypes = (mysql40,mysql41,mysql50,mysql51,mysql55,postgresql,interbase,odbc,oracle,sqlite3,mssql);
|
|
|
|
|
|
-const MySQLdbTypes = [mysql40,mysql41,mysql50,mysql51];
|
|
|
+const MySQLdbTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
|
|
|
DBTypesNames : Array [TSQLDBTypes] of String[19] =
|
|
|
- ('MYSQL40','MYSQL41','MYSQL50','MYSQL51','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3');
|
|
|
+ ('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3','MSSQL');
|
|
|
|
|
|
FieldtypeDefinitionsConst : Array [TFieldType] of String[20] =
|
|
|
(
|
|
@@ -24,26 +25,25 @@ const MySQLdbTypes = [mysql40,mysql41,mysql50,mysql51];
|
|
|
'',
|
|
|
'BOOLEAN',
|
|
|
'FLOAT',
|
|
|
- '',
|
|
|
- 'DECIMAL(18,4)',
|
|
|
+ '', // ftCurrency
|
|
|
+ 'DECIMAL(18,4)',// ftBCD
|
|
|
'DATE',
|
|
|
'TIME',
|
|
|
- 'TIMESTAMP',
|
|
|
- '',
|
|
|
+ 'TIMESTAMP', // ftDateTime
|
|
|
'',
|
|
|
'',
|
|
|
- 'BLOB',
|
|
|
- 'BLOB',
|
|
|
- 'BLOB',
|
|
|
'',
|
|
|
+ 'BLOB', // ftBlob
|
|
|
+ 'BLOB', // ftMemo
|
|
|
+ 'BLOB', // ftGraphic
|
|
|
'',
|
|
|
'',
|
|
|
'',
|
|
|
'',
|
|
|
- 'CHAR(10)',
|
|
|
'',
|
|
|
- 'BIGINT',
|
|
|
+ 'CHAR(10)', // ftFixedChar
|
|
|
'',
|
|
|
+ 'BIGINT', // ftLargeInt
|
|
|
'',
|
|
|
'',
|
|
|
'',
|
|
@@ -53,8 +53,9 @@ const MySQLdbTypes = [mysql40,mysql41,mysql50,mysql51];
|
|
|
'',
|
|
|
'',
|
|
|
'',
|
|
|
- 'TIMESTAMP',
|
|
|
- 'NUMERIC(18,6)',
|
|
|
+ '', // ftGuid
|
|
|
+ 'TIMESTAMP', // ftTimestamp
|
|
|
+ 'NUMERIC(18,6)',// ftFmtBCD
|
|
|
'',
|
|
|
''
|
|
|
);
|
|
@@ -111,6 +112,7 @@ begin
|
|
|
if SQLDbType = MYSQL41 then Fconnection := tMySQL41Connection.Create(nil);
|
|
|
if SQLDbType = MYSQL50 then Fconnection := tMySQL50Connection.Create(nil);
|
|
|
if SQLDbType = MYSQL51 then Fconnection := tMySQL51Connection.Create(nil);
|
|
|
+ if SQLDbType = MYSQL55 then Fconnection := tMySQL55Connection.Create(nil);
|
|
|
if SQLDbType in [mysql40,mysql41] then
|
|
|
begin
|
|
|
// Mysql versions prior to 5.0.3 removes the trailing spaces on varchar
|
|
@@ -155,8 +157,22 @@ begin
|
|
|
end;
|
|
|
if SQLDbType = ODBC then Fconnection := tODBCConnection.Create(nil);
|
|
|
if SQLDbType = ORACLE then Fconnection := TOracleConnection.Create(nil);
|
|
|
+ if SQLDbType = MSSQL then
|
|
|
+ begin
|
|
|
+ Fconnection := TMSSQLConnection.Create(nil);
|
|
|
+ FieldtypeDefinitions[ftBoolean] := 'BIT';
|
|
|
+ FieldtypeDefinitions[ftCurrency]:= 'MONEY';
|
|
|
+ FieldtypeDefinitions[ftDate] := 'DATETIME';
|
|
|
+ FieldtypeDefinitions[ftTime] := '';
|
|
|
+ FieldtypeDefinitions[ftDateTime]:= 'DATETIME';
|
|
|
+ FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
|
|
|
+ FieldtypeDefinitions[ftVarBytes]:= 'VARBINARY(10)';
|
|
|
+ FieldtypeDefinitions[ftBlob] := 'IMAGE';
|
|
|
+ FieldtypeDefinitions[ftMemo] := 'TEXT';
|
|
|
+ FieldtypeDefinitions[ftGraphic] := '';
|
|
|
+ end;
|
|
|
|
|
|
- if SQLDbType in [mysql40,mysql41,mysql50,mysql51,odbc,interbase] then
|
|
|
+ if SQLDbType in [mysql40,mysql41,mysql50,mysql51,mysql55,odbc,interbase] then
|
|
|
begin
|
|
|
// Some DB's do not support milliseconds in datetime and time fields.
|
|
|
// Firebird support miliseconds, see BUG 17199 (when resolved, then interbase can be excluded)
|
|
@@ -168,7 +184,7 @@ begin
|
|
|
testValues[ftDateTime,t] := copy(testValues[ftDateTime,t],1,19)+'.000';
|
|
|
end;
|
|
|
end;
|
|
|
- if SQLDbType in [postgresql,interbase] then
|
|
|
+ if SQLDbType in [postgresql,interbase,mssql] then
|
|
|
begin
|
|
|
// Some db's do not support times > 24:00:00
|
|
|
testTimeValues[3]:='13:25:15.000';
|
|
@@ -181,11 +197,15 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
- if SQLDbType in [sqlite3] then
|
|
|
- testValues[ftCurrency]:=testValues[ftBCD]; //decimal separator for currencies must be decimal point
|
|
|
+ // DecimalSeparator must correspond to monetary locale (lc_monetary) set on PostgreSQL server
|
|
|
+ // Here we assume, that locale on client side is same as locale on server
|
|
|
+ if SQLDbType in [postgresql] then
|
|
|
+ for t := 0 to testValuesCount-1 do
|
|
|
+ testValues[ftCurrency,t] := QuotedStr(CurrToStr(testCurrencyValues[t]));
|
|
|
|
|
|
// SQLite does not support fixed length CHAR datatype
|
|
|
// MySQL by default trimms trailing spaces on retrieval; so set sql-mode="PAD_CHAR_TO_FULL_LENGTH" - supported from MySQL 5.1.20
|
|
|
+ // MSSQL set SET ANSI_PADDING ON
|
|
|
if SQLDbType in [sqlite3] then
|
|
|
for t := 0 to testValuesCount-1 do
|
|
|
testValues[ftFixedChar,t] := PadRight(testValues[ftFixedChar,t], 10);
|
|
@@ -223,6 +243,7 @@ begin
|
|
|
begin
|
|
|
database := Fconnection;
|
|
|
transaction := Ftransaction;
|
|
|
+ PacketRecords := -1; // To avoid: "Connection is busy with results for another hstmt" (ODBC,MSSQL)
|
|
|
end;
|
|
|
end;
|
|
|
|
|
@@ -290,7 +311,10 @@ begin
|
|
|
begin
|
|
|
sql := sql + ',F' + Fieldtypenames[FType];
|
|
|
if testValues[FType,CountID] <> '' then
|
|
|
- sql1 := sql1 + ',' + QuotedStr(testValues[FType,CountID])
|
|
|
+ if FType in [ftCurrency] then
|
|
|
+ sql1 := sql1 + ',' + testValues[FType,CountID]
|
|
|
+ else
|
|
|
+ sql1 := sql1 + ',' + QuotedStr(testValues[FType,CountID])
|
|
|
else
|
|
|
sql1 := sql1 + ',NULL';
|
|
|
end;
|
|
@@ -302,7 +326,10 @@ begin
|
|
|
|
|
|
Ftransaction.Commit;
|
|
|
except
|
|
|
- if Ftransaction.Active then Ftransaction.Rollback
|
|
|
+ on E: Exception do begin
|
|
|
+ //writeln(E.Message);
|
|
|
+ if Ftransaction.Active then Ftransaction.Rollback;
|
|
|
+ end;
|
|
|
end;
|
|
|
end;
|
|
|
|