mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 07:29:25 +02:00
* Fix+Test for bug #27068 : coCheckRowsAffected
git-svn-id: trunk@29113 -
This commit is contained in:
parent
42a317ab73
commit
f00212c993
@ -117,6 +117,7 @@ Resourcestring
|
|||||||
SErrNoImplicitTransaction = 'Connection %s does not allow implicit transactions.';
|
SErrNoImplicitTransaction = 'Connection %s does not allow implicit transactions.';
|
||||||
SErrImplictTransactionStart = 'Error: attempt to implicitly start a transaction on Connection "%s", transaction "%s".';
|
SErrImplictTransactionStart = 'Error: attempt to implicitly start a transaction on Connection "%s", transaction "%s".';
|
||||||
SErrImplicitConnect = 'Error: attempt to implicitly activate connection "%s".';
|
SErrImplicitConnect = 'Error: attempt to implicitly activate connection "%s".';
|
||||||
|
SErrFailedToUpdateRecord = '%q: Failed to apply record updates: %d rows updated.';
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ type
|
|||||||
TConnOption = (sqSupportParams, sqSupportEmptyDatabaseName, sqEscapeSlash, sqEscapeRepeat, sqImplicitTransaction);
|
TConnOption = (sqSupportParams, sqSupportEmptyDatabaseName, sqEscapeSlash, sqEscapeRepeat, sqImplicitTransaction);
|
||||||
TConnOptions= set of TConnOption;
|
TConnOptions= set of TConnOption;
|
||||||
|
|
||||||
TConnectionOption = (coExplicitConnect);
|
TConnectionOption = (coExplicitConnect,coCheckRowsAffected);
|
||||||
TConnectionOptions = Set of TConnectionOption;
|
TConnectionOptions = Set of TConnectionOption;
|
||||||
|
|
||||||
TConnInfoType=(citAll=-1, citServerType, citServerVersion, citServerVersionString, citClientName, citClientVersion);
|
TConnInfoType=(citAll=-1, citServerType, citServerVersion, citServerVersionString, citClientName, citClientVersion);
|
||||||
@ -1671,6 +1671,8 @@ begin
|
|||||||
ApplyFieldUpdate(Query.Cursor,P as TSQLDBParam,Fld,B);
|
ApplyFieldUpdate(Query.Cursor,P as TSQLDBParam,Fld,B);
|
||||||
end;
|
end;
|
||||||
Qry.execute;
|
Qry.execute;
|
||||||
|
if (coCheckRowsAffected in Options) and (Qry.RowsAffected<>1) then
|
||||||
|
DatabaseErrorFmt(SErrFailedToUpdateRecord,[Qry.RowsAffected],Query);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLConnection.FreeFldBuffers(cursor: TSQLCursor);
|
procedure TSQLConnection.FreeFldBuffers(cursor: TSQLCursor);
|
||||||
|
@ -32,8 +32,11 @@ type
|
|||||||
FMyQ: TSQLQuery;
|
FMyQ: TSQLQuery;
|
||||||
procedure DoAfterPost(DataSet: TDataSet);
|
procedure DoAfterPost(DataSet: TDataSet);
|
||||||
Procedure Allow;
|
Procedure Allow;
|
||||||
|
Procedure DoApplyUpdates;
|
||||||
Procedure SetQueryOPtions;
|
Procedure SetQueryOPtions;
|
||||||
Procedure TrySetPacketRecords;
|
Procedure TrySetPacketRecords;
|
||||||
|
Protected
|
||||||
|
Procedure setup; override;
|
||||||
published
|
published
|
||||||
procedure TestMasterDetail;
|
procedure TestMasterDetail;
|
||||||
procedure TestUpdateServerIndexDefs;
|
procedure TestUpdateServerIndexDefs;
|
||||||
@ -42,6 +45,7 @@ type
|
|||||||
Procedure TestCheckSettingsOnlyWhenInactive;
|
Procedure TestCheckSettingsOnlyWhenInactive;
|
||||||
Procedure TestAutoApplyUpdatesPost;
|
Procedure TestAutoApplyUpdatesPost;
|
||||||
Procedure TestAutoApplyUpdatesDelete;
|
Procedure TestAutoApplyUpdatesDelete;
|
||||||
|
Procedure TestCheckRowsAffected;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTestTSQLConnection }
|
{ TTestTSQLConnection }
|
||||||
@ -219,6 +223,12 @@ begin
|
|||||||
FMyQ.PacketRecords:=10;
|
FMyQ.PacketRecords:=10;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Procedure TTestTSQLQuery.setup;
|
||||||
|
begin
|
||||||
|
inherited setup;
|
||||||
|
SQLDBConnector.Connection.Options:=[];
|
||||||
|
end;
|
||||||
|
|
||||||
Procedure TTestTSQLQuery.TestDisconnectedPacketRecords;
|
Procedure TTestTSQLQuery.TestDisconnectedPacketRecords;
|
||||||
begin
|
begin
|
||||||
with SQLDBConnector do
|
with SQLDBConnector do
|
||||||
@ -298,6 +308,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TTestTSQLQuery.TestAutoApplyUpdatesDelete;
|
Procedure TTestTSQLQuery.TestAutoApplyUpdatesDelete;
|
||||||
|
|
||||||
var Q: TSQLQuery;
|
var Q: TSQLQuery;
|
||||||
I, J : Integer;
|
I, J : Integer;
|
||||||
begin
|
begin
|
||||||
@ -333,6 +344,42 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Procedure TTestTSQLQuery.DoApplyUpdates;
|
||||||
|
|
||||||
|
begin
|
||||||
|
FMyQ.ApplyUpdates();
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure TTestTSQLQuery.TestCheckRowsAffected;
|
||||||
|
var Q: TSQLQuery;
|
||||||
|
I, J : Integer;
|
||||||
|
begin
|
||||||
|
// Test that if sqoAutoApplyUpdates is in QueryOptions, then Delete automatically does an ApplyUpdates
|
||||||
|
with SQLDBConnector do
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
ExecuteDirect('DROP table testdiscon');
|
||||||
|
except
|
||||||
|
// Ignore
|
||||||
|
end;
|
||||||
|
ExecuteDirect('create table testdiscon (id integer not null, a varchar(10), constraint pk_testdiscon primary key(id))');
|
||||||
|
Transaction.COmmit;
|
||||||
|
for I:=1 to 2 do
|
||||||
|
ExecuteDirect(Format('INSERT INTO testdiscon values (%d,''%.6d'')',[i,i]));
|
||||||
|
Transaction.COmmit;
|
||||||
|
SQLDBConnector.Connection.Options:=[coCheckRowsAffected];
|
||||||
|
Q := SQLDBConnector.Query;
|
||||||
|
Q.SQL.Text:='select * from testdiscon';
|
||||||
|
Q.DeleteSQL.Text:='delete from testdiscon';
|
||||||
|
Q.Open;
|
||||||
|
AssertEquals('Got all records',2,Q.RecordCount);
|
||||||
|
// Now check editing
|
||||||
|
Q.Delete;
|
||||||
|
FMyQ:=Q;
|
||||||
|
AssertException('Rowsaffected > 1 raises exception',EUpdateError,@DoApplyUpdates);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TTestTSQLConnection }
|
{ TTestTSQLConnection }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user