mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 03:49:59 +02:00
* Implemented RowsAffected and modified the test
git-svn-id: trunk@9098 -
This commit is contained in:
parent
515017ece6
commit
0fcf57fc1c
@ -42,6 +42,8 @@ type
|
|||||||
TArrayStringArray = Array of TStringArray;
|
TArrayStringArray = Array of TStringArray;
|
||||||
PArrayStringArray = ^TArrayStringArray;
|
PArrayStringArray = ^TArrayStringArray;
|
||||||
|
|
||||||
|
{ TSQLite3Connection }
|
||||||
|
|
||||||
TSQLite3Connection = class(TSQLConnection)
|
TSQLite3Connection = class(TSQLConnection)
|
||||||
private
|
private
|
||||||
fhandle: psqlite3;
|
fhandle: psqlite3;
|
||||||
@ -83,6 +85,7 @@ type
|
|||||||
procedure execsql(const asql: string);
|
procedure execsql(const asql: string);
|
||||||
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs; const TableName : string); // Differs from SQLDB.
|
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs; const TableName : string); // Differs from SQLDB.
|
||||||
function getprimarykeyfield(const atablename: string; const acursor: tsqlcursor): string;
|
function getprimarykeyfield(const atablename: string; const acursor: tsqlcursor): string;
|
||||||
|
function RowsAffected(cursor: TSQLCursor): TRowsCount; override;
|
||||||
public
|
public
|
||||||
function GetInsertID: int64;
|
function GetInsertID: int64;
|
||||||
published
|
published
|
||||||
@ -111,6 +114,8 @@ type
|
|||||||
Procedure UnPrepare;
|
Procedure UnPrepare;
|
||||||
Procedure Execute;
|
Procedure Execute;
|
||||||
Function Fetch : Boolean;
|
Function Fetch : Boolean;
|
||||||
|
public
|
||||||
|
RowsAffected : Largeint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure freebindstring(astring: pointer); cdecl;
|
procedure freebindstring(astring: pointer); cdecl;
|
||||||
@ -222,6 +227,7 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
if (fstate<=sqliteerrormax) then
|
if (fstate<=sqliteerrormax) then
|
||||||
checkerror(sqlite3_reset(fstatement));
|
checkerror(sqlite3_reset(fstatement));
|
||||||
|
RowsAffected:=sqlite3_changes(fhandle);
|
||||||
if (fstate=sqlite_row) then
|
if (fstate=sqlite_row) then
|
||||||
fstate:= sqliteerrormax; //first row
|
fstate:= sqliteerrormax; //first row
|
||||||
end;
|
end;
|
||||||
@ -697,6 +703,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSQLite3Connection.RowsAffected(cursor: TSQLCursor): TRowsCount;
|
||||||
|
begin
|
||||||
|
if assigned(cursor) then
|
||||||
|
Result := (cursor as TSQLite3Cursor).RowsAffected
|
||||||
|
else
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSQLite3Connection.UpdateIndexDefs(var IndexDefs: TIndexDefs;
|
procedure TSQLite3Connection.UpdateIndexDefs(var IndexDefs: TIndexDefs;
|
||||||
const TableName: string);
|
const TableName: string);
|
||||||
var
|
var
|
||||||
|
@ -921,8 +921,11 @@ begin
|
|||||||
Query.Open;
|
Query.Open;
|
||||||
AssertTrue(query.RowsAffected<>0); // It should return -1 or the number of selected rows.
|
AssertTrue(query.RowsAffected<>0); // It should return -1 or the number of selected rows.
|
||||||
query.Close;
|
query.Close;
|
||||||
AssertEquals(-1,query.RowsAffected);
|
AssertTrue(query.RowsAffected<>0); // It should return -1 or the same as the last time it was called.
|
||||||
Query.SQL.Text := 'delete from FPDEV2';
|
if (SQLDbType = sqlite3) then // sqlite doesn't count the rowsaffected if there is no where-clause
|
||||||
|
Query.SQL.Text := 'delete from FPDEV2 where 1'
|
||||||
|
else
|
||||||
|
Query.SQL.Text := 'delete from FPDEV2';
|
||||||
Query.ExecSQL;
|
Query.ExecSQL;
|
||||||
AssertEquals(2,query.RowsAffected);
|
AssertEquals(2,query.RowsAffected);
|
||||||
Query.SQL.Text := 'delete from FPDEV2';
|
Query.SQL.Text := 'delete from FPDEV2';
|
||||||
|
Loading…
Reference in New Issue
Block a user