fcl-db: tests:

* add new method CommitDDL to TSQLDBConnector. There is often used in tests "if SQLConnType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining;" so move this to separate method and use it.
* TODBCConnection in auto commit mode does not work well for Firebird/Interbase, so switch to manual commit mode.

git-svn-id: trunk@23075 -
This commit is contained in:
lacak 2012-11-28 12:47:09 +00:00
parent 595e413950
commit 6d8ac30a19
2 changed files with 48 additions and 41 deletions

View File

@ -96,6 +96,7 @@ type
public public
destructor Destroy; override; destructor Destroy; override;
constructor Create; override; constructor Create; override;
procedure CommitDDL;
property Connection : TSQLConnection read FConnection; property Connection : TSQLConnection read FConnection;
property Transaction : TSQLTransaction read FTransaction; property Transaction : TSQLTransaction read FTransaction;
property Query : TSQLQuery read FQuery; property Query : TSQLQuery read FQuery;
@ -151,7 +152,11 @@ begin
if SQLConnType = SQLITE3 then Fconnection := TSQLite3Connection.Create(nil); if SQLConnType = SQLITE3 then Fconnection := TSQLite3Connection.Create(nil);
if SQLConnType = POSTGRESQL then Fconnection := TPQConnection.Create(nil); if SQLConnType = POSTGRESQL then Fconnection := TPQConnection.Create(nil);
if SQLConnType = INTERBASE then Fconnection := TIBConnection.Create(nil); if SQLConnType = INTERBASE then Fconnection := TIBConnection.Create(nil);
if SQLConnType = ODBC then Fconnection := TODBCConnection.Create(nil); if SQLConnType = ODBC then
begin
Fconnection := TODBCConnection.Create(nil);
Fconnection.Params.Append('AutoCommit=false');
end;
{$IFNDEF Win64} {$IFNDEF Win64}
if SQLConnType = ORACLE then Fconnection := TOracleConnection.Create(nil); if SQLConnType = ORACLE then Fconnection := TOracleConnection.Create(nil);
{$ENDIF Win64} {$ENDIF Win64}
@ -176,9 +181,7 @@ begin
end; end;
if length(dbQuoteChars)>1 then if length(dbQuoteChars)>1 then
begin FieldNameQuoteChars:=dbQuoteChars;
FieldNameQuoteChars:=dbquotechars;
end;
Open; Open;
end; end;
@ -494,7 +497,6 @@ begin
'begin '+ 'begin '+
'drop table ' + ATableName + ' '+ 'drop table ' + ATableName + ' '+
'end'); 'end');
FTransaction.CommitRetaining;
end; end;
ssSybase: ssSybase:
begin begin
@ -513,6 +515,14 @@ begin
end; end;
end; end;
procedure TSQLDBConnector.CommitDDL;
begin
// Commits schema definition and manipulation statements;
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
if SQLServerType in [ssFirebird, ssInterbase] then
Transaction.CommitRetaining;
end;
destructor TSQLDBConnector.Destroy; destructor TSQLDBConnector.Destroy;
begin begin
if assigned(FTransaction) then if assigned(FTransaction) then
@ -523,7 +533,7 @@ begin
Fconnection.ExecuteDirect('DROP TABLE FPDEV2'); Fconnection.ExecuteDirect('DROP TABLE FPDEV2');
Ftransaction.Commit; Ftransaction.Commit;
Except Except
if Ftransaction.Active then Ftransaction.Rollback if Ftransaction.Active then Ftransaction.Rollback;
end; // try end; // try
end; end;
inherited Destroy; inherited Destroy;

View File

@ -221,13 +221,13 @@ begin
script.append('create table b (id int);'); script.append('create table b (id int);');
ExecuteScript; ExecuteScript;
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
if SQLConnType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
end; end;
finally finally
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('drop table a'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('drop table a');
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('drop table b'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('drop table b');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
if SQLConnType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
end; end;
end; end;
@ -260,8 +260,8 @@ procedure TTestFieldTypes.TestLargeRecordSize;
begin begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (plant varchar(8192),sampling_type varchar(8192),area varchar(8192), area_description varchar(8192), batch varchar(8192), sampling_datetime timestamp, status varchar(8192), batch_commentary varchar(8192))'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (plant varchar(8192),sampling_type varchar(8192),area varchar(8192), area_description varchar(8192), batch varchar(8192), sampling_datetime timestamp, status varchar(8192), batch_commentary varchar(8192))');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
if UpperCase(dbconnectorparams)='INTERBASE' then TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
with TSQLDBConnector(DBConnector).Query do with TSQLDBConnector(DBConnector).Query do
begin begin
@ -305,7 +305,7 @@ begin
else else
s := ', N19_0 NUMERIC(19,0)'; s := ', N19_0 NUMERIC(19,0)';
Connection.ExecuteDirect('create table FPDEV2 (FT NUMERIC(18,4), N4_2 NUMERIC(4,2), N9_3 NUMERIC(9,3), N9_5 NUMERIC(9,5), N18_0 NUMERIC(18,0), N18_3 NUMERIC(18,3), N18_5 NUMERIC(18,5)' + s + ')'); Connection.ExecuteDirect('create table FPDEV2 (FT NUMERIC(18,4), N4_2 NUMERIC(4,2), N9_3 NUMERIC(9,3), N9_5 NUMERIC(9,5), N18_0 NUMERIC(18,0), N18_3 NUMERIC(18,3), N18_5 NUMERIC(18,5)' + s + ')');
Transaction.CommitRetaining; CommitDDL;
with Query do with Query do
begin begin
@ -473,8 +473,6 @@ begin
else else
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testDateValues[i] + ''')'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testDateValues[i] + ''')');
// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
with TSQLDBConnector(DBConnector).Query do with TSQLDBConnector(DBConnector).Query do
begin begin
Open; Open;
@ -494,7 +492,7 @@ var s : string;
begin begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID int,FT '+FieldtypeDefinitions[ftblob]+')'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID int,FT '+FieldtypeDefinitions[ftblob]+')');
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For interbase TSQLDBConnector(DBConnector).CommitDDL;
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (ID,FT) values (1,''Test deze blob'')'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (ID,FT) values (1,''Test deze blob'')');
@ -540,8 +538,6 @@ begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''Test deze blob'')'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''Test deze blob'')');
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (Null)'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (Null)');
// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
with TSQLDBConnector(DBConnector).Query do with TSQLDBConnector(DBConnector).Query do
begin begin
Open; Open;
@ -586,8 +582,6 @@ begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''Test deze blob'')'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''Test deze blob'')');
// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
with TSQLDBConnector(DBConnector).Query do with TSQLDBConnector(DBConnector).Query do
begin begin
Open; Open;
@ -693,8 +687,8 @@ end;
procedure TTestFieldTypes.TestNullValues; procedure TTestFieldTypes.TestNullValues;
begin begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FIELD1 INT, FIELD2 INT)'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FIELD1 INT, FIELD2 INT)');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FIELD1) values (1)'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FIELD1) values (1)');
@ -714,8 +708,8 @@ procedure TTestFieldTypes.TestParamQuery;
begin begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FIELD1 INT, FIELD2 INT, FIELD3 INT, DECOY VARCHAR(30))'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FIELD1 INT, FIELD2 INT, FIELD3 INT, DECOY VARCHAR(30))');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
with TSQLDBConnector(DBConnector).Query do with TSQLDBConnector(DBConnector).Query do
begin begin
@ -867,8 +861,8 @@ begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID INT, FIELD1 '+ASQLTypeDecl+')'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID INT, FIELD1 '+ASQLTypeDecl+')');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
if SQLConnType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
with TSQLDBConnector(DBConnector).Query do with TSQLDBConnector(DBConnector).Query do
begin begin
@ -977,8 +971,8 @@ end;
procedure TTestFieldTypes.TestAggregates; procedure TTestFieldTypes.TestAggregates;
begin begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FIELD1 INT, FIELD2 INT)'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FIELD1 INT, FIELD2 INT)');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 values (1,1)'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 values (1,1)');
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 values (2,3)'); TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 values (2,3)');
@ -1018,7 +1012,7 @@ begin
begin begin
Connection.ExecuteDirect('create table FPDEV2 (FT ' +ASQLTypeDecl+ ')'); Connection.ExecuteDirect('create table FPDEV2 (FT ' +ASQLTypeDecl+ ')');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
Transaction.CommitRetaining; CommitDDL;
end; end;
end; end;
@ -1526,8 +1520,9 @@ begin
' NAME VARCHAR(16000),' + ' NAME VARCHAR(16000),' +
' PRIMARY KEY (ID) ' + ' PRIMARY KEY (ID) ' +
') '); ') ');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
query.sql.Text:='select * from FPDEV2'; query.sql.Text:='select * from FPDEV2';
Query.Open; Query.Open;
Query.InsertRecord([1,FieldValue]); Query.InsertRecord([1,FieldValue]);
@ -1548,8 +1543,9 @@ begin
' '+connection.FieldNameQuoteChars[0]+'3TEST'+connection.FieldNameQuoteChars[1]+' VARCHAR(10),' + ' '+connection.FieldNameQuoteChars[0]+'3TEST'+connection.FieldNameQuoteChars[1]+' VARCHAR(10),' +
' PRIMARY KEY ('+connection.FieldNameQuoteChars[0]+'2ID'+connection.FieldNameQuoteChars[0]+') ' + ' PRIMARY KEY ('+connection.FieldNameQuoteChars[0]+'2ID'+connection.FieldNameQuoteChars[0]+') ' +
') '); ') ');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
with query do with query do
begin begin
SQL.Text:='select * from FPDEV2'; SQL.Text:='select * from FPDEV2';
@ -1583,8 +1579,9 @@ begin
' '+Connection.FieldNameQuoteChars[0]+'NAME-TEST'+Connection.FieldNameQuoteChars[1]+' VARCHAR(250), ' + ' '+Connection.FieldNameQuoteChars[0]+'NAME-TEST'+Connection.FieldNameQuoteChars[1]+' VARCHAR(250), ' +
' PRIMARY KEY (ID) ' + ' PRIMARY KEY (ID) ' +
') '); ') ');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
Connection.ExecuteDirect('insert into FPDEV2(ID,'+Connection.FieldNameQuoteChars[0]+'NAME-TEST'+Connection.FieldNameQuoteChars[1]+') values (1,''test1'')'); Connection.ExecuteDirect('insert into FPDEV2(ID,'+Connection.FieldNameQuoteChars[0]+'NAME-TEST'+Connection.FieldNameQuoteChars[1]+') values (1,''test1'')');
Query.SQL.Text := 'select * from FPDEV2'; Query.SQL.Text := 'select * from FPDEV2';
Query.Open; Query.Open;
@ -1676,8 +1673,9 @@ begin
' NAME VARCHAR(250),' + ' NAME VARCHAR(250),' +
' PRIMARY KEY (ID) ' + ' PRIMARY KEY (ID) ' +
') '); ') ');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
Query.SQL.Text := 'insert into FPDEV2(ID,NAME) values (1,''test1'')'; Query.SQL.Text := 'insert into FPDEV2(ID,NAME) values (1,''test1'')';
Query.ExecSQL; Query.ExecSQL;
AssertEquals(1,query.RowsAffected); AssertEquals(1,query.RowsAffected);
@ -1736,7 +1734,7 @@ begin
begin begin
Connection.ExecuteDirect('create table FPDEV2 (id1 int, id2 int,vchar varchar(10))'); Connection.ExecuteDirect('create table FPDEV2 (id1 int, id2 int,vchar varchar(10))');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
Query.sql.Text := 'insert into FPDEV2 values(:id1,:id2,:vchar)'; Query.sql.Text := 'insert into FPDEV2 values(:id1,:id2,:vchar)';
query.params[0].asinteger := 1; query.params[0].asinteger := 1;
@ -1759,7 +1757,7 @@ begin
begin begin
Connection.ExecuteDirect('create table FPDEV2 (id1 int, id2 int, id3 int, id4 int,id5 int,id6 int,id7 int,id8 int, id9 int, id10 int, id11 int)'); Connection.ExecuteDirect('create table FPDEV2 (id1 int, id2 int, id3 int, id4 int,id5 int,id6 int,id7 int,id8 int, id9 int, id10 int, id11 int)');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
Query.sql.Text := 'insert into FPDEV2 values(:id1,:id2,:id3,:id4,:id5,:id6,:id7,:id8,:id9,:id10,:id11)'; Query.sql.Text := 'insert into FPDEV2 values(:id1,:id2,:id3,:id4,:id5,:id6,:id7,:id8,:id9,:id10,:id11)';
for i := 0 to 10 do for i := 0 to 10 do
@ -2089,9 +2087,8 @@ begin
' NAME VARCHAR(50), ' + ' NAME VARCHAR(50), ' +
' PRIMARY KEY (ID1, ID2)' + ' PRIMARY KEY (ID1, ID2)' +
') '); ') ');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
if SQLConnType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
ds := TSQLDBConnector(DBConnector).Query; ds := TSQLDBConnector(DBConnector).Query;
ds.sql.Text:='select * from FPDEV2'; ds.sql.Text:='select * from FPDEV2';
@ -2130,7 +2127,7 @@ begin
ExecSQL; ExecSQL;
try try
// Firebird/Interbase needs a commit after DDL: // Firebird/Interbase needs a commit after DDL:
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
SQL.Text := 'INSERT INTO FPDEV_TEMP(id) values (5)'; SQL.Text := 'INSERT INTO FPDEV_TEMP(id) values (5)';
ExecSQL; ExecSQL;
@ -2144,7 +2141,7 @@ begin
begin begin
SQL.Text := 'DROP TABLE FPDEV_TEMP'; SQL.Text := 'DROP TABLE FPDEV_TEMP';
ExecSQL; ExecSQL;
TSQLDBConnector(DBConnector).Transaction.CommitRetaining; TSQLDBConnector(DBConnector).CommitDDL;
end; end;
end; end;
end; end;