* Added some comments

* Tests are more generic, ie use BLOB for firebird, TEXT for postgresql etc
 * Added support for SQLite3

git-svn-id: trunk@8599 -
This commit is contained in:
joost 2007-09-21 21:39:09 +00:00
parent c88406c9e5
commit 10930a5165
3 changed files with 117 additions and 29 deletions

View File

@ -7,13 +7,58 @@ interface
uses
Classes, SysUtils, toolsunit,
db,
sqldb, ibconnection, mysql40conn, mysql41conn, mysql50conn, pqconnection,odbcconn,oracleconnection;
sqldb, ibconnection, mysql40conn, mysql41conn, mysql50conn, pqconnection,odbcconn,oracleconnection,sqlite3conn;
type TSQLDBTypes = (mysql40,mysql41,mysql50,postgresql,interbase,odbc,oracle);
type TSQLDBTypes = (mysql40,mysql41,mysql50,postgresql,interbase,odbc,oracle,sqlite3);
const MySQLdbTypes = [mysql40,mysql41,mysql50];
DBTypesNames : Array [TSQLDBTypes] of String[19] =
('MYSQL40','MYSQL41','MYSQL50','POSTGRESQL','INTERBASE','ODBC','ORACLE');
('MYSQL40','MYSQL41','MYSQL50','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3');
FieldtypeDefinitionsConst : Array [TFieldType] of String[15] =
(
'',
'VARCHAR(10)',
'SMALLINT',
'INTEGER',
'',
'',
'FLOAT',
'DECIMAL(18,4)',
'',
'DATE',
'TIMESTAMP',
'TIMESTAMP',
'',
'',
'',
'BLOB',
'BLOB',
'BLOB',
'',
'',
'',
'',
'',
'CHAR(10)',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'TIMESTAMP',
'',
'',
''
);
type
{ TSQLDBConnector }
@ -41,7 +86,8 @@ type
end;
var SQLDbType : TSQLDBTypes;
FieldtypeDefinitions : Array [TFieldType] of String[15];
implementation
{ TSQLDBConnector }
@ -51,11 +97,25 @@ var i : TSQLDBTypes;
begin
for i := low(DBTypesNames) to high(DBTypesNames) do
if UpperCase(dbconnectorparams) = DBTypesNames[i] then sqldbtype := i;
FieldtypeDefinitions := FieldtypeDefinitionsConst;
if SQLDbType = MYSQL40 then Fconnection := tMySQL40Connection.Create(nil);
if SQLDbType = MYSQL41 then Fconnection := tMySQL41Connection.Create(nil);
if SQLDbType = MYSQL50 then Fconnection := tMySQL50Connection.Create(nil);
if SQLDbType = POSTGRESQL then Fconnection := tpqConnection.Create(nil);
if SQLDbType = sqlite3 then
begin
Fconnection := TSQLite3Connection.Create(nil);
FieldtypeDefinitions[ftCurrency] := '';
FieldtypeDefinitions[ftFixedChar] := '';
end;
if SQLDbType = POSTGRESQL then
begin
Fconnection := tpqConnection.Create(nil);
FieldtypeDefinitions[ftBlob] := 'TEXT';
FieldtypeDefinitions[ftMemo] := 'TEXT';
FieldtypeDefinitions[ftGraphic] := '';
end;
if SQLDbType = INTERBASE then Fconnection := tIBConnection.Create(nil);
if SQLDbType = ODBC then Fconnection := tODBCConnection.Create(nil);
if SQLDbType = ORACLE then Fconnection := TOracleConnection.Create(nil);
@ -116,23 +176,41 @@ end;
procedure TSQLDBConnector.CreateFieldDataset;
var CountID : Integer;
FType : TFieldType;
Sql,sql1: String;
begin
try
Ftransaction.StartTransaction;
Fconnection.ExecuteDirect('create table FPDEV_FIELD ( ' +
' ID INT NOT NULL, ' +
' FSTRING VARCHAR(10), ' +
' FINTEGER INT, ' +
' FDATE DATE, ' +
' FDATETIME TIMESTAMP, ' +
' PRIMARY KEY (ID) ' +
') ');
Sql := 'create table FPDEV_FIELD (ID INT NOT NULL,';
for FType := low(TFieldType)to high(TFieldType) do
if FieldtypeDefinitions[FType]<>'' then
sql := sql + 'F' + Fieldtypenames[FType] + ' ' +FieldtypeDefinitions[FType]+ ',';
Sql := Sql + 'PRIMARY KEY (ID))';
FConnection.ExecuteDirect(Sql);
FTransaction.CommitRetaining;
for countID := 0 to testValuesCount-1 do
Fconnection.ExecuteDirect('insert into FPDEV_FIELD (ID,FSTRING,FINTEGER,FDATE,FDATETIME)' +
'values ('+inttostr(countID)+','''+testStringValues[CountID]+''','''+inttostr(testIntValues[CountID])+''','''+testDateValues[CountID]+''','''+testDateValues[CountID]+''')');
begin
Sql := 'insert into FPDEV_FIELD (ID';
Sql1 := 'values ('+IntToStr(countID);
for FType := low(TFieldType)to high(TFieldType) do
if FieldtypeDefinitions[FType]<>'' then
begin
sql := sql + ',F' + Fieldtypenames[FType];
if testValues[FType,CountID] <> '' then
sql1 := sql1 + ',''' + testValues[FType,CountID] + ''''
else
sql1 := sql1 + ',NULL';
end;
Sql := sql + ')';
Sql1 := sql1+ ')';
Fconnection.ExecuteDirect(sql + ' ' + sql1);
end;
Ftransaction.Commit;
except

View File

@ -396,8 +396,7 @@ procedure TTestFieldTypes.TestChangeBlob;
var s : string;
begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID int,FT blob)');
// TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID int,FT text)');
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID int,FT '+FieldtypeDefinitions[ftblob]+')');
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For interbase
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (ID,FT) values (1,''Test deze blob'')');
@ -438,8 +437,7 @@ end;
procedure TTestFieldTypes.TestBlobGetText;
begin
CreateTableWithFieldType(ftBlob,'BLOB');
// CreateTableWithFieldType(ftBlob,'TEXT');
CreateTableWithFieldType(ftBlob,FieldtypeDefinitions[ftBlob]);
TestFieldDeclaration(ftBlob,0);
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''Test deze blob'')');
@ -468,7 +466,7 @@ var
ASQL : TSQLQuery;
begin
CreateTableWithFieldType(ftBlob,'BLOB');
CreateTableWithFieldType(ftBlob,FieldtypeDefinitions[ftBlob]);
// CreateTableWithFieldType(ftBlob,'TEXT');
TestFieldDeclaration(ftBlob,0);
@ -496,8 +494,7 @@ var
i : byte;
begin
CreateTableWithFieldType(ftBlob,'BLOB');
// CreateTableWithFieldType(ftBlob,'TEXT');
CreateTableWithFieldType(ftBlob,FieldtypeDefinitions[ftBlob]);
TestFieldDeclaration(ftBlob,0);
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''Test deze blob'')');
@ -555,7 +552,7 @@ var
i, corrTestValueCount : byte;
begin
CreateTableWithFieldType(ftDateTime,'TIMESTAMP');
CreateTableWithFieldType(ftDateTime,FieldtypeDefinitions[ftDateTime]);
TestFieldDeclaration(ftDateTime,8);
if SQLDbType=mysql40 then corrTestValueCount := testValuesCount-21
@ -742,6 +739,7 @@ begin
with TSQLDBConnector(DBConnector).Query do
begin
PacketRecords := -1;
sql.clear;
sql.append('insert into FPDEV2 (ID,FIELD1) values (:id,:field1)');
@ -911,8 +909,7 @@ var
ASQL : TSQLQuery;
begin
CreateTableWithFieldType(ftBlob,'BLOB');
// CreateTableWithFieldType(ftBlob,'TEXT');
CreateTableWithFieldType(ftBlob,FieldtypeDefinitions[ftBlob]);
TestFieldDeclaration(ftBlob,0);
ASQL := DBConnector.GetNDataset(True,1) as tsqlquery;
@ -987,6 +984,7 @@ begin
end;
procedure TTestFieldTypes.TestParametersAndDates;
// See bug 7205
begin
with TSQLDBConnector(DBConnector).Query do
begin

View File

@ -147,10 +147,12 @@ var dbtype,
dbname,
dbuser,
dbhostname,
dbpassword : string;
DataEvents : string;
DBConnector : TDBConnector;
dbpassword : string;
DataEvents : string;
DBConnector : TDBConnector;
testValues : Array [TFieldType,0..testvaluescount -1] of string;
procedure InitialiseDBConnector;
implementation
@ -217,7 +219,17 @@ end;
procedure InitialiseDBConnector;
var DBConnectorClass : TPersistentClass;
i : integer;
begin
testValues[ftString] := testStringValues;
testValues[ftDate] := testDateValues;
for i := 0 to testValuesCount-1 do
begin
testValues[ftFloat,i] := FloatToStr(testFloatValues[i]);
testValues[ftSmallint,i] := IntToStr(testSmallIntValues[i]);
testValues[ftInteger,i] := IntToStr(testIntValues[i]);
end;
if dbconnectorname = '' then raise Exception.Create('There is no db-connector specified');
DBConnectorClass := GetClass('T'+dbconnectorname+'DBConnector');
if assigned(DBConnectorClass) then