fcl-db: tests: rename test tables to "FPDEV2", which is automatically cleaned up upon test completion.

git-svn-id: trunk@29462 -
This commit is contained in:
lacak 2015-01-13 12:04:55 +00:00
parent 16744dc6dc
commit e8c40ee106

View File

@ -180,14 +180,13 @@ begin
// Test also that an edit still works. // Test also that an edit still works.
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
Transaction.Commit; Transaction.Commit;
for I:=1 to 20 do for I:=1 to 20 do
ExecuteDirect(Format('INSERT INTO testdiscon values (%d,''%.6d'')',[i,i])); ExecuteDirect(Format('INSERT INTO FPDEV2 values (%d,''%.6d'')',[i,i]));
Transaction.Commit; Transaction.Commit;
Q := SQLDBConnector.Query; Q := SQLDBConnector.Query;
Q.SQL.Text:='select * from testdiscon'; Q.SQL.Text:='select * from FPDEV2';
Q.Options:=[sqoKeepOpenOnCommit]; Q.Options:=[sqoKeepOpenOnCommit];
AssertEquals('PacketRecords forced to -1',-1,Q.PacketRecords); AssertEquals('PacketRecords forced to -1',-1,Q.PacketRecords);
Q.Open; Q.Open;
@ -203,7 +202,7 @@ begin
Q.ApplyUpdates; Q.ApplyUpdates;
AssertTrue('Have no more updates pending',Q.UpdateStatus=usUnmodified); AssertTrue('Have no more updates pending',Q.UpdateStatus=usUnmodified);
Q.Close; Q.Close;
Q.SQL.Text:='select * from testdiscon where (id=20) and (a=''abc'')'; Q.SQL.Text:='select * from FPDEV2 where (id=20) and (a=''abc'')';
Q.Open; Q.Open;
AssertTrue('Have modified data record in database', not (Q.EOF AND Q.BOF)); AssertTrue('Have modified data record in database', not (Q.EOF AND Q.BOF));
end; end;
@ -240,13 +239,12 @@ begin
// Check that we can only set QueryOptions when the query is inactive. // Check that we can only set QueryOptions when the query is inactive.
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
Transaction.COmmit; Transaction.COmmit;
ExecuteDirect(Format('INSERT INTO testdiscon values (%d,''%.6d'')',[1,1])); ExecuteDirect(Format('INSERT INTO FPDEV2 values (%d,''%.6d'')',[1,1]));
Transaction.COmmit; Transaction.COmmit;
FMyQ := SQLDBConnector.Query; FMyQ := SQLDBConnector.Query;
FMyQ.SQL.Text:='select * from testdiscon'; FMyQ.SQL.Text:='select * from FPDEV2';
FMyQ := SQLDBConnector.Query; FMyQ := SQLDBConnector.Query;
FMyQ.OPen; FMyQ.OPen;
AssertException('Cannot set packetrecords when sqoDisconnected is active',EDatabaseError,@SetQueryOptions); AssertException('Cannot set packetrecords when sqoDisconnected is active',EDatabaseError,@SetQueryOptions);
@ -266,15 +264,14 @@ begin
// Test also that POST afterpost event is backwards compatible. // Test also that POST afterpost event is backwards compatible.
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
Transaction.COmmit; Transaction.COmmit;
for I:=1 to 2 do for I:=1 to 2 do
ExecuteDirect(Format('INSERT INTO testdiscon values (%d,''%.6d'')',[i,i])); ExecuteDirect(Format('INSERT INTO FPDEV2 values (%d,''%.6d'')',[i,i]));
Transaction.COmmit; Transaction.COmmit;
Q := SQLDBConnector.Query; Q := SQLDBConnector.Query;
FMyQ:=Q; // so th event handler can reach it. FMyQ:=Q; // so th event handler can reach it.
Q.SQL.Text:='select * from testdiscon'; Q.SQL.Text:='select * from FPDEV2';
Q.Options:=[sqoAutoApplyUpdates]; Q.Options:=[sqoAutoApplyUpdates];
// We must test that in AfterPost, the modification is still there, for backwards compatibilty // We must test that in AfterPost, the modification is still there, for backwards compatibilty
Q.AfterPost:=@DoAfterPost; Q.AfterPost:=@DoAfterPost;
@ -287,7 +284,7 @@ begin
Q.Post; Q.Post;
AssertTrue('Have no more updates pending',Q.UpdateStatus=usUnmodified); AssertTrue('Have no more updates pending',Q.UpdateStatus=usUnmodified);
Q.Close; Q.Close;
Q.SQL.Text:='select * from testdiscon where (id=2) and (a=''abc'')'; Q.SQL.Text:='select * from FPDEV2 where (id=2) and (a=''abc'')';
Q.Open; Q.Open;
AssertTrue('Have modified data record in database',not (Q.EOF AND Q.BOF)); AssertTrue('Have modified data record in database',not (Q.EOF AND Q.BOF));
end; end;
@ -302,15 +299,14 @@ begin
// Test that if sqoAutoApplyUpdates is in QueryOptions, then Delete automatically does an ApplyUpdates // Test that if sqoAutoApplyUpdates is in QueryOptions, then Delete automatically does an ApplyUpdates
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
Transaction.COmmit; Transaction.COmmit;
for I:=1 to 2 do for I:=1 to 2 do
ExecuteDirect(Format('INSERT INTO testdiscon values (%d,''%.6d'')',[i,i])); ExecuteDirect(Format('INSERT INTO FPDEV2 values (%d,''%.6d'')',[i,i]));
Transaction.COmmit; Transaction.COmmit;
Q := SQLDBConnector.Query; Q := SQLDBConnector.Query;
FMyQ:=Q; // so th event handler can reach it. FMyQ:=Q; // so th event handler can reach it.
Q.SQL.Text:='select * from testdiscon'; Q.SQL.Text:='select * from FPDEV2';
Q.Options:=[sqoAutoApplyUpdates]; Q.Options:=[sqoAutoApplyUpdates];
// We must test that in AfterPost, the modification is still there, for backwards compatibilty // We must test that in AfterPost, the modification is still there, for backwards compatibilty
Q.AfterPost:=@DoAfterPost; Q.AfterPost:=@DoAfterPost;
@ -321,7 +317,7 @@ begin
Q.Delete; Q.Delete;
AssertTrue('Have no more updates pending',Q.UpdateStatus=usUnmodified); AssertTrue('Have no more updates pending',Q.UpdateStatus=usUnmodified);
Q.Close; Q.Close;
Q.SQL.Text:='select * from testdiscon where (id=2)'; Q.SQL.Text:='select * from FPDEV2 where (id=2)';
Q.Open; Q.Open;
AssertTrue('Data record is deleted in database', (Q.EOF AND Q.BOF)); AssertTrue('Data record is deleted in database', (Q.EOF AND Q.BOF));
end; end;
@ -340,22 +336,21 @@ begin
// Test that if sqoAutoApplyUpdates is in QueryOptions, then Delete automatically does an ApplyUpdates // Test that if sqoAutoApplyUpdates is in QueryOptions, then Delete automatically does an ApplyUpdates
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
Transaction.COmmit; Transaction.COmmit;
for I:=1 to 2 do for I:=1 to 2 do
ExecuteDirect(Format('INSERT INTO testdiscon values (%d,''%.6d'')',[i,i])); ExecuteDirect(Format('INSERT INTO FPDEV2 values (%d,''%.6d'')',[i,i]));
Transaction.COmmit; Transaction.COmmit;
SQLDBConnector.Connection.Options:=[scoApplyUpdatesChecksRowsAffected]; SQLDBConnector.Connection.Options:=[scoApplyUpdatesChecksRowsAffected];
Q := SQLDBConnector.Query; Q := SQLDBConnector.Query;
Q.SQL.Text:='select * from testdiscon'; Q.SQL.Text:='select * from FPDEV2';
Q.DeleteSQL.Text:='delete from testdiscon'; Q.DeleteSQL.Text:='delete from FPDEV2';
Q.Open; Q.Open;
AssertEquals('Got all records',2,Q.RecordCount); AssertEquals('Got all records',2,Q.RecordCount);
// Now check editing // Now check editing
Q.Delete; Q.Delete;
FMyQ:=Q; FMyQ:=Q;
AssertException('Rowsaffected > 1 raises exception',EUpdateError,@DoApplyUpdates); AssertException('RowsAffected > 1 raises exception',EUpdateError,@DoApplyUpdates);
end; end;
end; end;
@ -365,15 +360,14 @@ var
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
Query.Options:=[sqoAutoCommit]; Query.Options:=[sqoAutoCommit];
for I:=1 to 2 do for I:=1 to 2 do
begin begin
Query.SQL.Text:=Format('INSERT INTO testdiscon values (%d,''%.6d'');',[i,i]); Query.SQL.Text:=Format('INSERT INTO FPDEV2 values (%d,''%.6d'');',[i,i]);
Query.Prepare; Query.Prepare;
Query.ExecSQL; Query.ExecSQL;
// We do not commit anything explicitly. // We do not commit anything explicitly.
@ -384,7 +378,7 @@ begin
Connection.Close; Connection.Close;
Connection.Open; Connection.Open;
Query.SQL.Text:='SELECT COUNT(*) from testdiscon'; Query.SQL.Text:='SELECT COUNT(*) from FPDEV2';
Query.Open; Query.Open;
AssertEquals('Records haven''t been committed to database', 2, Query.Fields[0].AsInteger); AssertEquals('Records haven''t been committed to database', 2, Query.Fields[0].AsInteger);
end; end;
@ -397,23 +391,32 @@ var
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdefval'); ExecuteDirect('create table FPDEV2 (id integer not null primary key, a varchar(5) default ''abcde'', b integer default 1)');
ExecuteDirect('create table testdefval (id integer not null, a varchar(10) default ''abcde'', constraint pk_testdefval primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
Q:=SQLDBConnector.Query; Q:=SQLDBConnector.Query;
Q.SQL.Text:='select * from testdefval'; Q.SQL.Text:='select * from FPDEV2';
Q.InsertSQL.Text:='insert into testdefval (id) values (:id)'; Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
Q.RefreshSQL.Text:='SELECT a FROM testdefval WHERE (id=:id)'; Q.RefreshSQL.Text:='SELECT a,b FROM FPDEV2 WHERE (id=:id)';
Q.Open; Q.Open;
Q.Insert; Q.Insert; // #1 record
Q.FieldByName('id').AsInteger:=1; Q.FieldByName('id').AsInteger:=1;
Q.Post; Q.Post;
AssertTrue('Field value has not been fetched after post',Q.FieldByName('a').IsNull); Q.Append; // #2 record
Q.FieldByName('id').AsInteger:=2;
Q.Post;
AssertTrue('Field value has not been fetched after Post', Q.FieldByName('a').IsNull);
Q.ApplyUpdates(0); Q.ApplyUpdates(0);
AssertEquals('Still on correct field',1,Q.FieldByName('id').AsInteger); // #2 record:
AssertEquals('Field value has been fetched from the database ','abcde',Q.FieldByName('a').AsString); AssertEquals('Still on correct field', 2, Q.FieldByName('id').AsInteger);
AssertEquals('Field value has been fetched from the database', 'abcde', Q.FieldByName('a').AsString);
AssertEquals('Field value has been fetched from the database', 1, Q.FieldByName('b').AsInteger);
Q.Prior;
// #1 record:
AssertEquals('Still on correct field', 1, Q.FieldByName('id').AsInteger);
AssertEquals('Field value has been fetched from the database', 'abcde', Q.FieldByName('a').AsString);
AssertEquals('Field value has been fetched from the database', 1, Q.FieldByName('b').AsInteger);
end; end;
Procedure TTestTSQLQuery.TestGeneratedRefreshSQL; Procedure TTestTSQLQuery.TestGeneratedRefreshSQL;
@ -424,14 +427,13 @@ var
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdefval'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdefval (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint pk_testdefval primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
Q:=SQLDBConnector.Query; Q:=SQLDBConnector.Query;
Q.SQL.Text:='select * from testdefval'; Q.SQL.Text:='select * from FPDEV2';
Q.InsertSQL.Text:='insert into testdefval (id) values (:id)'; Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
Q.Open; Q.Open;
With Q.FieldByName('id') do With Q.FieldByName('id') do
ProviderFlags:=ProviderFlags+[pfInKey]; ProviderFlags:=ProviderFlags+[pfInKey];
@ -456,14 +458,13 @@ var
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdefval'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdefval (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint pk_testdefval primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
Q:=SQLDBConnector.Query; Q:=SQLDBConnector.Query;
Q.SQL.Text:='select * from testdefval'; Q.SQL.Text:='select * from FPDEV2';
Q.InsertSQL.Text:='insert into testdefval (id) values (:id)'; Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
Q.Open; Q.Open;
With Q.FieldByName('id') do With Q.FieldByName('id') do
ProviderFlags:=ProviderFlags+[pfInKey]; ProviderFlags:=ProviderFlags+[pfInKey];
@ -483,14 +484,13 @@ Procedure TTestTSQLQuery.TestGeneratedRefreshSQLNoKey;
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdefval'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdefval (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint pk_testdefval primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
FMyQ:=SQLDBConnector.Query; FMyQ:=SQLDBConnector.Query;
FMyQ.SQL.Text:='select * from testdefval'; FMyQ.SQL.Text:='select * from FPDEV2';
FMyQ.InsertSQL.Text:='insert into testdefval (id) values (:id)'; FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
FMyQ.Open; FMyQ.Open;
With FMyQ.FieldByName('id') do With FMyQ.FieldByName('id') do
ProviderFlags:=ProviderFlags-[pfInKey]; ProviderFlags:=ProviderFlags-[pfInKey];
@ -507,18 +507,17 @@ Procedure TTestTSQLQuery.TestRefreshSQLMultipleRecords;
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdefval'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdefval (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint pk_testdefval primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
ExecuteDirect('insert into testdefval (id) values (123)'); ExecuteDirect('insert into FPDEV2 (id) values (123)');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
FMyQ:=SQLDBConnector.Query; FMyQ:=SQLDBConnector.Query;
FMyQ.SQL.Text:='select * from testdefval'; FMyQ.SQL.Text:='select * from FPDEV2';
FMyQ.InsertSQL.Text:='insert into testdefval (id) values (:id)'; FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
FMyQ.RefreshSQL.Text:='select * from testdefval'; FMyQ.RefreshSQL.Text:='select * from FPDEV2';
FMyQ.Open; FMyQ.Open;
With FMyQ.FieldByName('id') do With FMyQ.FieldByName('id') do
ProviderFlags:=ProviderFlags+[pfInKey]; ProviderFlags:=ProviderFlags+[pfInKey];
@ -534,18 +533,17 @@ Procedure TTestTSQLQuery.TestRefreshSQLNoRecords;
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdefval'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdefval (id integer not null, a varchar(10) default ''abcde'', b varchar(5) default ''fgh'', constraint pk_testdefval primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
ExecuteDirect('insert into testdefval (id) values (123)'); ExecuteDirect('insert into FPDEV2 (id) values (123)');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
FMyQ:=SQLDBConnector.Query; FMyQ:=SQLDBConnector.Query;
FMyQ.SQL.Text:='select * from testdefval'; FMyQ.SQL.Text:='select * from FPDEV2';
FMyQ.InsertSQL.Text:='insert into testdefval (id) values (:id)'; FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
FMyQ.RefreshSQL.Text:='select * from testdefval where 1=2'; FMyQ.RefreshSQL.Text:='select * from FPDEV2 where 1=2';
FMyQ.Open; FMyQ.Open;
With FMyQ.FieldByName('id') do With FMyQ.FieldByName('id') do
ProviderFlags:=ProviderFlags+[pfInKey]; ProviderFlags:=ProviderFlags+[pfInKey];
@ -575,7 +573,6 @@ begin
else else
Ignore(STestNotApplicable); Ignore(STestNotApplicable);
end; end;
TryDropIfExist('FPDEV2');
ExecuteDirect('create table FPDEV2 (id '+datatype+' primary key, f varchar(5))'); ExecuteDirect('create table FPDEV2 (id '+datatype+' primary key, f varchar(5))');
CommitDDL; CommitDDL;
end; end;
@ -651,7 +648,6 @@ end;
procedure TTestTSQLConnection.TestImplicitTransactionOK; procedure TTestTSQLConnection.TestImplicitTransactionOK;
var var
Q : TSQLQuery; Q : TSQLQuery;
T : TSQLTransaction; T : TSQLTransaction;
@ -659,8 +655,7 @@ var
begin begin
with SQLDBConnector do with SQLDBConnector do
begin begin
TryDropIfExist('testdiscon'); ExecuteDirect('create table FPDEV2 (id integer not null, a varchar(10), constraint PK_FPDEV2 primary key(id))');
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
if Transaction.Active then if Transaction.Active then
Transaction.Commit; Transaction.Commit;
end; end;
@ -668,7 +663,7 @@ begin
Q:=SQLDBConnector.Query; Q:=SQLDBConnector.Query;
for I:=1 to 2 do for I:=1 to 2 do
begin begin
Q.SQL.Text:=Format('INSERT INTO testdiscon values (%d,''%.6d'');',[i,i]); Q.SQL.Text:=Format('INSERT INTO FPDEV2 values (%d,''%.6d'');',[i,i]);
Q.Prepare; Q.Prepare;
Q.ExecSQL; Q.ExecSQL;
// We do not commit anything explicitly. // We do not commit anything explicitly.
@ -681,7 +676,7 @@ begin
Q.Transaction:=T; Q.Transaction:=T;
Q.Database:=SQLDBConnector.Connection; Q.Database:=SQLDBConnector.Connection;
T.Database:=SQLDBConnector.Connection; T.Database:=SQLDBConnector.Connection;
Q.SQL.text:='SELECT COUNT(*) from testdiscon'; Q.SQL.text:='SELECT COUNT(*) from FPDEV2';
Q.Open; Q.Open;
AssertEquals('Records have been committed to database',2,Q.Fields[0].AsInteger); AssertEquals('Records have been committed to database',2,Q.Fields[0].AsInteger);
finally finally