mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 04:19:07 +02:00
- Added TSQLTransaction.params
git-svn-id: trunk@837 -
This commit is contained in:
parent
db68fb68b4
commit
509593eb49
@ -15,12 +15,6 @@ uses
|
|||||||
{$EndIf}
|
{$EndIf}
|
||||||
|
|
||||||
type
|
type
|
||||||
TAccessMode = (amReadWrite, amReadOnly);
|
|
||||||
TIsolationLevel = (ilConcurrent, ilConsistent, ilReadCommittedRecV,
|
|
||||||
ilReadCommitted);
|
|
||||||
TLockResolution = (lrWait, lrNoWait);
|
|
||||||
TTableReservation = (trNone, trSharedLockRead, trSharedLockWrite,
|
|
||||||
trProtectedLockRead, trProtectedLockWrite);
|
|
||||||
|
|
||||||
TIBCursor = Class(TSQLCursor)
|
TIBCursor = Class(TSQLCursor)
|
||||||
protected
|
protected
|
||||||
@ -38,10 +32,6 @@ type
|
|||||||
TransactionHandle : pointer;
|
TransactionHandle : pointer;
|
||||||
TPB : string; // Transaction parameter buffer
|
TPB : string; // Transaction parameter buffer
|
||||||
Status : array [0..19] of ISC_STATUS;
|
Status : array [0..19] of ISC_STATUS;
|
||||||
AccessMode : TAccessMode;
|
|
||||||
IsolationLevel : TIsolationLevel;
|
|
||||||
LockResolution : TLockResolution;
|
|
||||||
TableReservation : TTableReservation;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TIBConnection = class (TSQLConnection)
|
TIBConnection = class (TSQLConnection)
|
||||||
@ -54,7 +44,6 @@ type
|
|||||||
procedure AllocSQLDA(var aSQLDA : PXSQLDA;Count : integer);
|
procedure AllocSQLDA(var aSQLDA : PXSQLDA;Count : integer);
|
||||||
procedure TranslateFldType(SQLType, SQLLen, SQLScale : integer; var LensSet : boolean;
|
procedure TranslateFldType(SQLType, SQLLen, SQLScale : integer; var LensSet : boolean;
|
||||||
var TrType : TFieldType; var TrLen : word);
|
var TrType : TFieldType; var TrLen : word);
|
||||||
procedure SetTPB(trans : TIBtrans);
|
|
||||||
// conversion methods
|
// conversion methods
|
||||||
procedure GetDateTime(CurrBuff, Buffer : pointer; AType : integer);
|
procedure GetDateTime(CurrBuff, Buffer : pointer; AType : integer);
|
||||||
procedure GetFloat(CurrBuff, Buffer : pointer; Field : TFieldDef);
|
procedure GetFloat(CurrBuff, Buffer : pointer; Field : TFieldDef);
|
||||||
@ -80,7 +69,7 @@ type
|
|||||||
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;
|
||||||
function StartdbTransaction(trans : TSQLHandle) : boolean; override;
|
function StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; override;
|
||||||
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;
|
||||||
@ -135,43 +124,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIBConnection.SetTPB(trans : TIBtrans);
|
|
||||||
begin
|
|
||||||
with trans do
|
|
||||||
begin
|
|
||||||
TPB := chr(isc_tpb_version3);
|
|
||||||
|
|
||||||
case AccessMode of
|
|
||||||
amReadWrite : TPB := TPB + chr(isc_tpb_write);
|
|
||||||
amReadOnly : TPB := TPB + chr(isc_tpb_read);
|
|
||||||
end;
|
|
||||||
|
|
||||||
case IsolationLevel of
|
|
||||||
ilConsistent : TPB := TPB + chr(isc_tpb_consistency);
|
|
||||||
ilConcurrent : TPB := TPB + chr(isc_tpb_concurrency);
|
|
||||||
ilReadCommittedRecV : TPB := TPB + chr(isc_tpb_read_committed) +
|
|
||||||
chr(isc_tpb_rec_version);
|
|
||||||
ilReadCommitted : TPB := TPB + chr(isc_tpb_read_committed) +
|
|
||||||
chr(isc_tpb_no_rec_version);
|
|
||||||
end;
|
|
||||||
|
|
||||||
case LockResolution of
|
|
||||||
lrWait : TPB := TPB + chr(isc_tpb_wait);
|
|
||||||
lrNoWait : TPB := TPB + chr(isc_tpb_nowait);
|
|
||||||
end;
|
|
||||||
|
|
||||||
case TableReservation of
|
|
||||||
trSharedLockRead : TPB := TPB + chr(isc_tpb_shared) +
|
|
||||||
chr(isc_tpb_lock_read);
|
|
||||||
trSharedLockWrite : TPB := TPB + chr(isc_tpb_shared) +
|
|
||||||
chr(isc_tpb_lock_write);
|
|
||||||
trProtectedLockRead : TPB := TPB + chr(isc_tpb_protected) +
|
|
||||||
chr(isc_tpb_lock_read);
|
|
||||||
trProtectedLockWrite : TPB := TPB + chr(isc_tpb_protected) +
|
|
||||||
chr(isc_tpb_lock_write);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor TIBConnection.Create(AOwner : TComponent);
|
constructor TIBConnection.Create(AOwner : TComponent);
|
||||||
|
|
||||||
@ -203,18 +155,49 @@ begin
|
|||||||
else result := true;
|
else result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIBConnection.StartDBTransaction(trans : TSQLHandle) : boolean;
|
function TIBConnection.StartDBTransaction(trans : TSQLHandle;AParams : String) : boolean;
|
||||||
var
|
var
|
||||||
DBHandle : pointer;
|
DBHandle : pointer;
|
||||||
tr : TIBTrans;
|
tr : TIBTrans;
|
||||||
|
i : integer;
|
||||||
|
s : string;
|
||||||
begin
|
begin
|
||||||
result := false;
|
result := false;
|
||||||
|
|
||||||
DBHandle := GetHandle;
|
DBHandle := GetHandle;
|
||||||
tr := trans as TIBtrans;
|
tr := trans as TIBtrans;
|
||||||
SetTPB(tr);
|
|
||||||
with tr do
|
with tr do
|
||||||
begin
|
begin
|
||||||
|
TPB := chr(isc_tpb_version3);
|
||||||
|
|
||||||
|
i := 1;
|
||||||
|
s := ExtractSubStr(AParams,i,stdWordDelims);
|
||||||
|
while s <> '' do
|
||||||
|
begin
|
||||||
|
if s='isc_tpb_write' then TPB := TPB + chr(isc_tpb_write)
|
||||||
|
else if s='isc_tpb_read' then TPB := TPB + chr(isc_tpb_read)
|
||||||
|
else if s='isc_tpb_consistency' then TPB := TPB + chr(isc_tpb_consistency)
|
||||||
|
else if s='isc_tpb_concurrency' then TPB := TPB + chr(isc_tpb_concurrency)
|
||||||
|
else if s='isc_tpb_read_committed' then TPB := TPB + chr(isc_tpb_read_committed)
|
||||||
|
else if s='isc_tpb_rec_version' then TPB := TPB + chr(isc_tpb_rec_version)
|
||||||
|
else if s='isc_tpb_no_rec_version' then TPB := TPB + chr(isc_tpb_no_rec_version)
|
||||||
|
else if s='isc_tpb_wait' then TPB := TPB + chr(isc_tpb_wait)
|
||||||
|
else if s='isc_tpb_nowait' then TPB := TPB + chr(isc_tpb_nowait)
|
||||||
|
else if s='isc_tpb_shared' then TPB := TPB + chr(isc_tpb_shared)
|
||||||
|
else if s='isc_tpb_protected' then TPB := TPB + chr(isc_tpb_protected)
|
||||||
|
else if s='isc_tpb_exclusive' then TPB := TPB + chr(isc_tpb_exclusive)
|
||||||
|
else if s='isc_tpb_lock_read' then TPB := TPB + chr(isc_tpb_lock_read)
|
||||||
|
else if s='isc_tpb_lock_write' then TPB := TPB + chr(isc_tpb_lock_write)
|
||||||
|
else if s='isc_tpb_verb_time' then TPB := TPB + chr(isc_tpb_verb_time)
|
||||||
|
else if s='isc_tpb_commit_time' then TPB := TPB + chr(isc_tpb_commit_time)
|
||||||
|
else if s='isc_tpb_ignore_limbo' then TPB := TPB + chr(isc_tpb_ignore_limbo)
|
||||||
|
else if s='isc_tpb_autocommit' then TPB := TPB + chr(isc_tpb_autocommit)
|
||||||
|
else if s='isc_tpb_restart_requests' then TPB := TPB + chr(isc_tpb_restart_requests)
|
||||||
|
else if s='isc_tpb_no_auto_undo' then TPB := TPB + chr(isc_tpb_no_auto_undo);
|
||||||
|
s := ExtractSubStr(AParams,i,stdWordDelims);
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
TransactionHandle := nil;
|
TransactionHandle := nil;
|
||||||
|
|
||||||
if isc_start_transaction(@Status, @TransactionHandle, 1,
|
if isc_start_transaction(@Status, @TransactionHandle, 1,
|
||||||
|
@ -64,7 +64,7 @@ Type
|
|||||||
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;
|
||||||
function StartdbTransaction(trans : TSQLHandle) : boolean; override;
|
function StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; override;
|
||||||
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;
|
||||||
@ -631,7 +631,7 @@ begin
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMySQLConnection.StartdbTransaction(trans: TSQLHandle): boolean;
|
function TMySQLConnection.StartdbTransaction(trans: TSQLHandle; AParams : string): boolean;
|
||||||
begin
|
begin
|
||||||
// Do nothing
|
// Do nothing
|
||||||
end;
|
end;
|
||||||
|
@ -57,7 +57,7 @@ type
|
|||||||
function RollBack(trans : TSQLHandle) : boolean; override;
|
function RollBack(trans : TSQLHandle) : boolean; override;
|
||||||
function Commit(trans : TSQLHandle) : boolean; override;
|
function Commit(trans : TSQLHandle) : boolean; override;
|
||||||
procedure CommitRetaining(trans : TSQLHandle); override;
|
procedure CommitRetaining(trans : TSQLHandle); override;
|
||||||
function StartdbTransaction(trans : TSQLHandle) : boolean; override;
|
function StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; 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;
|
||||||
public
|
public
|
||||||
@ -159,7 +159,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPQConnection.StartdbTransaction(trans : TSQLHandle) : boolean;
|
function TPQConnection.StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean;
|
||||||
var
|
var
|
||||||
res : PPGresult;
|
res : PPGresult;
|
||||||
tr : TPQTrans;
|
tr : TPQTrans;
|
||||||
|
@ -94,7 +94,7 @@ type
|
|||||||
function GetTransactionHandle(trans : TSQLHandle): pointer; virtual; abstract;
|
function GetTransactionHandle(trans : TSQLHandle): pointer; virtual; abstract;
|
||||||
function Commit(trans : TSQLHandle) : boolean; virtual; abstract;
|
function Commit(trans : TSQLHandle) : boolean; virtual; abstract;
|
||||||
function RollBack(trans : TSQLHandle) : boolean; virtual; abstract;
|
function RollBack(trans : TSQLHandle) : boolean; virtual; abstract;
|
||||||
function StartdbTransaction(trans : TSQLHandle) : boolean; virtual; abstract;
|
function StartdbTransaction(trans : TSQLHandle; aParams : string) : boolean; virtual; abstract;
|
||||||
procedure CommitRetaining(trans : TSQLHandle); virtual; abstract;
|
procedure CommitRetaining(trans : TSQLHandle); virtual; abstract;
|
||||||
procedure RollBackRetaining(trans : TSQLHandle); virtual; abstract;
|
procedure RollBackRetaining(trans : TSQLHandle); virtual; abstract;
|
||||||
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); virtual;
|
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); virtual;
|
||||||
@ -131,6 +131,7 @@ type
|
|||||||
private
|
private
|
||||||
FTrans : TSQLHandle;
|
FTrans : TSQLHandle;
|
||||||
FAction : TCommitRollbackAction;
|
FAction : TCommitRollbackAction;
|
||||||
|
FParams : TStringList;
|
||||||
protected
|
protected
|
||||||
function GetHandle : Pointer; virtual;
|
function GetHandle : Pointer; virtual;
|
||||||
Procedure SetDatabase (Value : TDatabase); override;
|
Procedure SetDatabase (Value : TDatabase); override;
|
||||||
@ -147,6 +148,7 @@ type
|
|||||||
published
|
published
|
||||||
property Action : TCommitRollbackAction read FAction write FAction;
|
property Action : TCommitRollbackAction read FAction write FAction;
|
||||||
property Database;
|
property Database;
|
||||||
|
property Params : TStringList read FParams write FParams;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSQLQuery }
|
{ TSQLQuery }
|
||||||
@ -427,17 +429,19 @@ begin
|
|||||||
Db.Open;
|
Db.Open;
|
||||||
if not assigned(FTrans) then FTrans := Db.AllocateTransactionHandle;
|
if not assigned(FTrans) then FTrans := Db.AllocateTransactionHandle;
|
||||||
|
|
||||||
if Db.StartdbTransaction(FTrans) then OpenTrans;
|
if Db.StartdbTransaction(FTrans,FParams.CommaText) then OpenTrans;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TSQLTransaction.Create(AOwner : TComponent);
|
constructor TSQLTransaction.Create(AOwner : TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
|
FParams := TStringList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TSQLTransaction.Destroy;
|
destructor TSQLTransaction.Destroy;
|
||||||
begin
|
begin
|
||||||
Rollback;
|
Rollback;
|
||||||
|
FreeAndNil(FParams);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user