mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-30 15:00:16 +02:00
fcl-db: tests: Follow rev.30691 (Renamed sqoPreferRefresh to sqoRefreshUsingSelect) Bug #28017
git-svn-id: trunk@30795 -
This commit is contained in:
parent
6755c36a7b
commit
93802cf5ee
@ -17,8 +17,8 @@ type
|
|||||||
{ TSQLDBTestCase }
|
{ TSQLDBTestCase }
|
||||||
|
|
||||||
TSQLDBTestCase = class(TTestCase)
|
TSQLDBTestCase = class(TTestCase)
|
||||||
private
|
private
|
||||||
function GetSQLDBConnector: TSQLDBConnector;
|
function GetSQLDBConnector: TSQLDBConnector;
|
||||||
protected
|
protected
|
||||||
procedure SetUp; override;
|
procedure SetUp; override;
|
||||||
procedure TearDown; override;
|
procedure TearDown; override;
|
||||||
@ -46,10 +46,10 @@ type
|
|||||||
Procedure TestAutoApplyUpdatesDelete;
|
Procedure TestAutoApplyUpdatesDelete;
|
||||||
Procedure TestCheckRowsAffected;
|
Procedure TestCheckRowsAffected;
|
||||||
Procedure TestAutoCommit;
|
Procedure TestAutoCommit;
|
||||||
Procedure TestRefreshSQL;
|
|
||||||
Procedure TestGeneratedRefreshSQL;
|
Procedure TestGeneratedRefreshSQL;
|
||||||
Procedure TestGeneratedRefreshSQL1Field;
|
Procedure TestGeneratedRefreshSQL1Field;
|
||||||
Procedure TestGeneratedRefreshSQLNoKey;
|
Procedure TestGeneratedRefreshSQLNoKey;
|
||||||
|
Procedure TestRefreshSQL;
|
||||||
Procedure TestRefreshSQLMultipleRecords;
|
Procedure TestRefreshSQLMultipleRecords;
|
||||||
Procedure TestRefreshSQLNoRecords;
|
Procedure TestRefreshSQLNoRecords;
|
||||||
Procedure TestFetchAutoInc;
|
Procedure TestFetchAutoInc;
|
||||||
@ -200,7 +200,7 @@ begin
|
|||||||
|
|
||||||
Q := SQLDBConnector.Query;
|
Q := SQLDBConnector.Query;
|
||||||
Q.SQL.Text:='select * from FPDEV2';
|
Q.SQL.Text:='select * from FPDEV2';
|
||||||
Q.Options:=[sqoKeepOpenOnCommit,sqoPreferRefresh];
|
Q.Options:=[sqoKeepOpenOnCommit,sqoRefreshUsingSelect];
|
||||||
AssertEquals('PacketRecords forced to -1',-1,Q.PacketRecords);
|
AssertEquals('PacketRecords forced to -1',-1,Q.PacketRecords);
|
||||||
Q.Open;
|
Q.Open;
|
||||||
AssertEquals('Got all records',20,Q.RecordCount);
|
AssertEquals('Got all records',20,Q.RecordCount);
|
||||||
@ -392,42 +392,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestTSQLQuery.TestRefreshSQL;
|
|
||||||
var
|
|
||||||
Q: TSQLQuery;
|
|
||||||
|
|
||||||
begin
|
|
||||||
with SQLDBConnector do
|
|
||||||
begin
|
|
||||||
ExecuteDirect('create table FPDEV2 (id integer not null primary key, a varchar(5) default ''abcde'', b integer default 1)');
|
|
||||||
if Transaction.Active then
|
|
||||||
Transaction.Commit;
|
|
||||||
end;
|
|
||||||
Q:=SQLDBConnector.Query;
|
|
||||||
Q.OPtions:=Q.OPtions+[sqoPreferRefresh];
|
|
||||||
Q.SQL.Text:='select * from FPDEV2';
|
|
||||||
Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
|
||||||
Q.RefreshSQL.Text:='SELECT a,b FROM FPDEV2 WHERE (id=:id)';
|
|
||||||
Q.Open;
|
|
||||||
Q.Insert; // #1 record
|
|
||||||
Q.FieldByName('id').AsInteger:=1;
|
|
||||||
Q.Post;
|
|
||||||
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);
|
|
||||||
// #2 record:
|
|
||||||
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;
|
|
||||||
|
|
||||||
procedure TTestTSQLQuery.TestGeneratedRefreshSQL;
|
procedure TTestTSQLQuery.TestGeneratedRefreshSQL;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -443,7 +407,7 @@ begin
|
|||||||
Q:=SQLDBConnector.Query;
|
Q:=SQLDBConnector.Query;
|
||||||
Q.SQL.Text:='select * from FPDEV2';
|
Q.SQL.Text:='select * from FPDEV2';
|
||||||
Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
||||||
Q.OPtions:=Q.OPtions+[sqoPreferRefresh];
|
Q.Options:=Q.Options+[sqoRefreshUsingSelect];
|
||||||
Q.Open;
|
Q.Open;
|
||||||
With Q.FieldByName('id') do
|
With Q.FieldByName('id') do
|
||||||
ProviderFlags:=ProviderFlags+[pfInKey];
|
ProviderFlags:=ProviderFlags+[pfInKey];
|
||||||
@ -475,7 +439,7 @@ begin
|
|||||||
Q:=SQLDBConnector.Query;
|
Q:=SQLDBConnector.Query;
|
||||||
Q.SQL.Text:='select * from FPDEV2';
|
Q.SQL.Text:='select * from FPDEV2';
|
||||||
Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
||||||
Q.OPtions:=Q.OPtions+[sqoPreferRefresh];
|
Q.Options:=Q.Options+[sqoRefreshUsingSelect];
|
||||||
Q.Open;
|
Q.Open;
|
||||||
With Q.FieldByName('id') do
|
With Q.FieldByName('id') do
|
||||||
ProviderFlags:=ProviderFlags+[pfInKey];
|
ProviderFlags:=ProviderFlags+[pfInKey];
|
||||||
@ -502,7 +466,7 @@ begin
|
|||||||
FMyQ:=SQLDBConnector.Query;
|
FMyQ:=SQLDBConnector.Query;
|
||||||
FMyQ.SQL.Text:='select * from FPDEV2';
|
FMyQ.SQL.Text:='select * from FPDEV2';
|
||||||
FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
||||||
FMyQ.OPtions:=FMyQ.OPtions+[sqoPreferRefresh];
|
FMyQ.Options:=FMyQ.Options+[sqoRefreshUsingSelect];
|
||||||
FMyQ.Open;
|
FMyQ.Open;
|
||||||
With FMyQ.FieldByName('id') do
|
With FMyQ.FieldByName('id') do
|
||||||
ProviderFlags:=ProviderFlags-[pfInKey];
|
ProviderFlags:=ProviderFlags-[pfInKey];
|
||||||
@ -514,6 +478,41 @@ begin
|
|||||||
AssertException('Cannot refresh without primary key',EUpdateError,@DoApplyUpdates);
|
AssertException('Cannot refresh without primary key',EUpdateError,@DoApplyUpdates);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestTSQLQuery.TestRefreshSQL;
|
||||||
|
var
|
||||||
|
Q: TSQLQuery;
|
||||||
|
|
||||||
|
begin
|
||||||
|
with SQLDBConnector do
|
||||||
|
begin
|
||||||
|
ExecuteDirect('create table FPDEV2 (id integer not null primary key, a varchar(5) default ''abcde'', b integer default 1)');
|
||||||
|
if Transaction.Active then
|
||||||
|
Transaction.Commit;
|
||||||
|
end;
|
||||||
|
Q:=SQLDBConnector.Query;
|
||||||
|
Q.SQL.Text:='select * from FPDEV2';
|
||||||
|
Q.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
||||||
|
Q.RefreshSQL.Text:='SELECT a,b FROM FPDEV2 WHERE (id=:id)';
|
||||||
|
Q.Open;
|
||||||
|
Q.Insert; // #1 record
|
||||||
|
Q.FieldByName('id').AsInteger:=1;
|
||||||
|
Q.Post;
|
||||||
|
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);
|
||||||
|
// #2 record:
|
||||||
|
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;
|
||||||
|
|
||||||
procedure TTestTSQLQuery.TestRefreshSQLMultipleRecords;
|
procedure TTestTSQLQuery.TestRefreshSQLMultipleRecords;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -527,7 +526,6 @@ begin
|
|||||||
Transaction.Commit;
|
Transaction.Commit;
|
||||||
end;
|
end;
|
||||||
FMyQ:=SQLDBConnector.Query;
|
FMyQ:=SQLDBConnector.Query;
|
||||||
FMyQ.OPtions:=FMyQ.OPtions+[sqoPreferRefresh];
|
|
||||||
FMyQ.SQL.Text:='select * from FPDEV2';
|
FMyQ.SQL.Text:='select * from FPDEV2';
|
||||||
FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
||||||
FMyQ.RefreshSQL.Text:='select * from FPDEV2';
|
FMyQ.RefreshSQL.Text:='select * from FPDEV2';
|
||||||
@ -554,7 +552,6 @@ begin
|
|||||||
Transaction.Commit;
|
Transaction.Commit;
|
||||||
end;
|
end;
|
||||||
FMyQ:=SQLDBConnector.Query;
|
FMyQ:=SQLDBConnector.Query;
|
||||||
FMyQ.OPtions:=FMyQ.OPtions+[sqoPreferRefresh];
|
|
||||||
FMyQ.SQL.Text:='select * from FPDEV2';
|
FMyQ.SQL.Text:='select * from FPDEV2';
|
||||||
FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
FMyQ.InsertSQL.Text:='insert into FPDEV2 (id) values (:id)';
|
||||||
FMyQ.RefreshSQL.Text:='select * from FPDEV2 where 1=2';
|
FMyQ.RefreshSQL.Text:='select * from FPDEV2 where 1=2';
|
||||||
@ -950,7 +947,7 @@ end;
|
|||||||
|
|
||||||
function TSQLDBTestCase.GetSQLDBConnector: TSQLDBConnector;
|
function TSQLDBTestCase.GetSQLDBConnector: TSQLDBConnector;
|
||||||
begin
|
begin
|
||||||
Result:=DBConnector as TSQLDBConnector;
|
Result := DBConnector as TSQLDBConnector;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLDBTestCase.SetUp;
|
procedure TSQLDBTestCase.SetUp;
|
||||||
|
Loading…
Reference in New Issue
Block a user