mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 18:49:16 +02:00
* Patch from Andrey Gusev to implement TSQLQuery.GetRowsaffected + test
git-svn-id: trunk@8843 -
This commit is contained in:
parent
bfca4e67fa
commit
c39b663201
@ -115,6 +115,7 @@ Type
|
|||||||
procedure CommitRetaining(trans : TSQLHandle); override;
|
procedure CommitRetaining(trans : TSQLHandle); override;
|
||||||
procedure RollBackRetaining(trans : TSQLHandle); override;
|
procedure RollBackRetaining(trans : TSQLHandle); override;
|
||||||
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); override;
|
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); override;
|
||||||
|
function RowsAffected(cursor: TSQLCursor): TRowsCount; override;
|
||||||
Public
|
Public
|
||||||
constructor Create(AOwner : TComponent); override;
|
constructor Create(AOwner : TComponent); override;
|
||||||
procedure CreateDB; override;
|
procedure CreateDB; override;
|
||||||
@ -844,6 +845,11 @@ begin
|
|||||||
qry.free;
|
qry.free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TConnectionName.RowsAffected(cursor: TSQLCursor): TRowsCount;
|
||||||
|
begin
|
||||||
|
Result := (cursor as TCursorName).RowsAffected;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TConnectionName.Create(AOwner: TComponent);
|
constructor TConnectionName.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
|
@ -26,6 +26,8 @@ type TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns,
|
|||||||
TConnOption = (sqSupportParams,sqEscapeSlash,sqEscapeRepeat);
|
TConnOption = (sqSupportParams,sqEscapeSlash,sqEscapeRepeat);
|
||||||
TConnOptions= set of TConnOption;
|
TConnOptions= set of TConnOption;
|
||||||
|
|
||||||
|
TRowsCount = LargeInt;
|
||||||
|
|
||||||
type
|
type
|
||||||
TSQLConnection = class;
|
TSQLConnection = class;
|
||||||
TSQLTransaction = class;
|
TSQLTransaction = class;
|
||||||
@ -105,6 +107,7 @@ type
|
|||||||
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); virtual;
|
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); virtual;
|
||||||
function GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string; virtual;
|
function GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string; virtual;
|
||||||
procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField; cursor: TSQLCursor; ATransaction : TSQLTransaction); virtual; abstract;
|
procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField; cursor: TSQLCursor; ATransaction : TSQLTransaction); virtual; abstract;
|
||||||
|
function RowsAffected(cursor: TSQLCursor): TRowsCount; virtual;
|
||||||
public
|
public
|
||||||
property Handle: Pointer read GetHandle;
|
property Handle: Pointer read GetHandle;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -241,6 +244,7 @@ type
|
|||||||
procedure SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string); virtual;
|
procedure SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string); virtual;
|
||||||
property Prepared : boolean read IsPrepared;
|
property Prepared : boolean read IsPrepared;
|
||||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||||
|
function RowsAffected: TRowsCount; virtual;
|
||||||
protected
|
protected
|
||||||
|
|
||||||
// redeclared data set properties
|
// redeclared data set properties
|
||||||
@ -394,6 +398,7 @@ type
|
|||||||
|
|
||||||
procedure FreeFldBuffers(cursor : TSQLCursor); override;
|
procedure FreeFldBuffers(cursor : TSQLCursor); override;
|
||||||
function LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; override;
|
function LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; override;
|
||||||
|
function RowsAffected(cursor: TSQLCursor): TRowsCount; override;
|
||||||
function GetTransactionHandle(trans : TSQLHandle): pointer; override;
|
function GetTransactionHandle(trans : TSQLHandle): pointer; override;
|
||||||
function Commit(trans : TSQLHandle) : boolean; override;
|
function Commit(trans : TSQLHandle) : boolean; override;
|
||||||
function RollBack(trans : TSQLHandle) : boolean; override;
|
function RollBack(trans : TSQLHandle) : boolean; override;
|
||||||
@ -554,6 +559,10 @@ begin
|
|||||||
qry.free;
|
qry.free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSQLConnection.RowsAffected(cursor: TSQLCursor): TRowsCount;
|
||||||
|
begin
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSQLConnection.GetTableNames(List: TStrings; SystemTables: Boolean);
|
procedure TSQLConnection.GetTableNames(List: TStrings; SystemTables: Boolean);
|
||||||
begin
|
begin
|
||||||
@ -917,6 +926,14 @@ begin
|
|||||||
result := (Database as tSQLConnection).LoadField(FCursor,FieldDef,buffer, Createblob)
|
result := (Database as tSQLConnection).LoadField(FCursor,FieldDef,buffer, Createblob)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomSQLQuery.RowsAffected: TRowsCount;
|
||||||
|
begin
|
||||||
|
Result := -1;
|
||||||
|
if not Assigned(Database) then Exit;
|
||||||
|
//assert(Database is TSQLConnection);
|
||||||
|
Result := (Database as TSQLConnection).RowsAffected(FCursor);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
|
procedure TCustomSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
|
||||||
begin
|
begin
|
||||||
// not implemented - sql dataset
|
// not implemented - sql dataset
|
||||||
@ -1855,6 +1872,12 @@ begin
|
|||||||
Result:=FProxy.LoadField(cursor, FieldDef, buffer, CreateBlob);
|
Result:=FProxy.LoadField(cursor, FieldDef, buffer, CreateBlob);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSQLConnector.RowsAffected(cursor: TSQLCursor): TRowsCount;
|
||||||
|
begin
|
||||||
|
CheckProxy;
|
||||||
|
Result := FProxy.RowsAffected(cursor);
|
||||||
|
end;
|
||||||
|
|
||||||
function TSQLConnector.GetTransactionHandle(trans: TSQLHandle): pointer;
|
function TSQLConnector.GetTransactionHandle(trans: TSQLHandle): pointer;
|
||||||
begin
|
begin
|
||||||
CheckProxy;
|
CheckProxy;
|
||||||
|
@ -26,6 +26,7 @@ type
|
|||||||
procedure TearDown; override;
|
procedure TearDown; override;
|
||||||
procedure RunTest; override;
|
procedure RunTest; override;
|
||||||
published
|
published
|
||||||
|
procedure TestRowsAffected;
|
||||||
procedure TestStringsReplace;
|
procedure TestStringsReplace;
|
||||||
procedure TestCircularParams;
|
procedure TestCircularParams;
|
||||||
procedure Test11Params;
|
procedure Test11Params;
|
||||||
@ -870,6 +871,33 @@ begin
|
|||||||
inherited RunTest;
|
inherited RunTest;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestFieldTypes.TestRowsAffected;
|
||||||
|
begin
|
||||||
|
with TSQLDBConnector(DBConnector) do
|
||||||
|
begin
|
||||||
|
Connection.ExecuteDirect('create table FPDEV2 ( ' +
|
||||||
|
' ID INT NOT NULL , ' +
|
||||||
|
' NAME VARCHAR(250), ' +
|
||||||
|
' PRIMARY KEY (ID) ' +
|
||||||
|
') ');
|
||||||
|
Query.SQL.Text := 'insert into FPDEV2(ID,NAME) values (1,''test1'')';
|
||||||
|
Query.ExecSQL;
|
||||||
|
AssertEquals(1,query.RowsAffected);
|
||||||
|
Query.SQL.Text := 'insert into FPDEV2(ID,NAME) values (2,''test2'')';
|
||||||
|
Query.ExecSQL;
|
||||||
|
AssertEquals(1,query.RowsAffected);
|
||||||
|
Query.SQL.Text := 'update FPDEV2 set NAME=''NewTest''';
|
||||||
|
Query.ExecSQL;
|
||||||
|
AssertEquals(2,query.RowsAffected);
|
||||||
|
Query.SQL.Text := 'delete from FPDEV2';
|
||||||
|
Query.ExecSQL;
|
||||||
|
AssertEquals(2,query.RowsAffected);
|
||||||
|
Query.SQL.Text := 'delete from FPDEV2';
|
||||||
|
Query.ExecSQL;
|
||||||
|
AssertEquals(0,query.RowsAffected);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestFieldTypes.TestStringsReplace;
|
procedure TTestFieldTypes.TestStringsReplace;
|
||||||
begin
|
begin
|
||||||
AssertEquals('dit is een string',StringsReplace('dit was een string',['was'],['is'],[]));
|
AssertEquals('dit is een string',StringsReplace('dit was een string',['was'],['is'],[]));
|
||||||
|
Loading…
Reference in New Issue
Block a user