mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-19 10:50:39 +02:00
fcl-db: interbase: add TransactionHandle to TIBCursor (needed for further work) + unify naming (DatabaseHandle, TransactionHandle, StatementHandle)
git-svn-id: trunk@35232 -
This commit is contained in:
parent
42cde51805
commit
67f38f374b
@ -36,7 +36,8 @@ type
|
|||||||
TIBCursor = Class(TSQLCursor)
|
TIBCursor = Class(TSQLCursor)
|
||||||
protected
|
protected
|
||||||
Status : array [0..19] of ISC_STATUS;
|
Status : array [0..19] of ISC_STATUS;
|
||||||
Statement : pointer;
|
TransactionHandle : pointer;
|
||||||
|
StatementHandle : pointer;
|
||||||
SQLDA : PXSQLDA;
|
SQLDA : PXSQLDA;
|
||||||
in_SQLDA : PXSQLDA;
|
in_SQLDA : PXSQLDA;
|
||||||
ParamBinding : array of integer;
|
ParamBinding : array of integer;
|
||||||
@ -55,7 +56,7 @@ type
|
|||||||
TIBConnection = class (TSQLConnection)
|
TIBConnection = class (TSQLConnection)
|
||||||
private
|
private
|
||||||
FCheckTransactionParams: Boolean;
|
FCheckTransactionParams: Boolean;
|
||||||
FSQLDatabaseHandle : pointer;
|
FDatabaseHandle : pointer;
|
||||||
FStatus : array [0..19] of ISC_STATUS;
|
FStatus : array [0..19] of ISC_STATUS;
|
||||||
FDatabaseInfo : TDatabaseInfo;
|
FDatabaseInfo : TDatabaseInfo;
|
||||||
FDialect : integer;
|
FDialect : integer;
|
||||||
@ -366,7 +367,7 @@ begin
|
|||||||
|
|
||||||
ConnectFB;
|
ConnectFB;
|
||||||
|
|
||||||
if isc_drop_database(@FStatus[0], @FSQLDatabaseHandle) <> 0 then
|
if isc_drop_database(@FStatus[0], @FDatabaseHandle) <> 0 then
|
||||||
CheckError('DropDB', FStatus);
|
CheckError('DropDB', FStatus);
|
||||||
|
|
||||||
{$IfDef LinkDynamically}
|
{$IfDef LinkDynamically}
|
||||||
@ -431,11 +432,11 @@ begin
|
|||||||
if not Connected then
|
if not Connected then
|
||||||
begin
|
begin
|
||||||
ResetDatabaseInfo;
|
ResetDatabaseInfo;
|
||||||
FSQLDatabaseHandle := nil;
|
FDatabaseHandle := nil;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if isc_detach_database(@FStatus[0], @FSQLDatabaseHandle) <> 0 then
|
if isc_detach_database(@FStatus[0], @FDatabaseHandle) <> 0 then
|
||||||
CheckError('Close', FStatus);
|
CheckError('Close', FStatus);
|
||||||
{$IfDef LinkDynamically}
|
{$IfDef LinkDynamically}
|
||||||
ReleaseIBase60;
|
ReleaseIBase60;
|
||||||
@ -498,7 +499,7 @@ begin
|
|||||||
ReqBuf[1] := isc_info_version;
|
ReqBuf[1] := isc_info_version;
|
||||||
ReqBuf[2] := isc_info_db_sql_dialect;
|
ReqBuf[2] := isc_info_db_sql_dialect;
|
||||||
ReqBuf[3] := isc_info_end;
|
ReqBuf[3] := isc_info_end;
|
||||||
if isc_database_info(@FStatus[0], @FSQLDatabaseHandle, Length(ReqBuf),
|
if isc_database_info(@FStatus[0], @FDatabaseHandle, Length(ReqBuf),
|
||||||
pchar(@ReqBuf[0]), SizeOf(ResBuf), pchar(@ResBuf[0])) <> 0 then
|
pchar(@ReqBuf[0]), SizeOf(ResBuf), pchar(@ResBuf[0])) <> 0 then
|
||||||
CheckError('CacheServerInfo', FStatus);
|
CheckError('CacheServerInfo', FStatus);
|
||||||
x := 0;
|
x := 0;
|
||||||
@ -623,12 +624,11 @@ begin
|
|||||||
if Length(CharSet) > 0 then
|
if Length(CharSet) > 0 then
|
||||||
DPB := DPB + Chr(isc_dpb_lc_ctype) + Chr(Length(CharSet)) + CharSet;
|
DPB := DPB + Chr(isc_dpb_lc_ctype) + Chr(Length(CharSet)) + CharSet;
|
||||||
|
|
||||||
FSQLDatabaseHandle := nil;
|
FDatabaseHandle := nil;
|
||||||
if HostName <> '' then ADatabaseName := HostName+':'+DatabaseName
|
if HostName <> '' then ADatabaseName := HostName+':'+DatabaseName
|
||||||
else ADatabaseName := DatabaseName;
|
else ADatabaseName := DatabaseName;
|
||||||
if isc_attach_database(@FStatus[0], Length(ADatabaseName), @ADatabaseName[1],
|
if isc_attach_database(@FStatus[0], Length(ADatabaseName), @ADatabaseName[1],
|
||||||
@FSQLDatabaseHandle,
|
@FDatabaseHandle, Length(DPB), @DPB[1]) <> 0 then
|
||||||
Length(DPB), @DPB[1]) <> 0 then
|
|
||||||
CheckError('DoInternalConnect', FStatus);
|
CheckError('DoInternalConnect', FStatus);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -737,7 +737,7 @@ var curs : TIBCursor;
|
|||||||
begin
|
begin
|
||||||
curs := TIBCursor.create;
|
curs := TIBCursor.create;
|
||||||
curs.sqlda := nil;
|
curs.sqlda := nil;
|
||||||
curs.statement := nil;
|
curs.StatementHandle := nil;
|
||||||
curs.FPrepared := False;
|
curs.FPrepared := False;
|
||||||
AllocSQLDA(curs.SQLDA,0);
|
AllocSQLDA(curs.SQLDA,0);
|
||||||
result := curs;
|
result := curs;
|
||||||
@ -762,8 +762,7 @@ end;
|
|||||||
|
|
||||||
procedure TIBConnection.PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams);
|
procedure TIBConnection.PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams);
|
||||||
|
|
||||||
var dh : pointer;
|
var DatabaseHandle : pointer;
|
||||||
tr : pointer;
|
|
||||||
x : Smallint;
|
x : Smallint;
|
||||||
info_request : string;
|
info_request : string;
|
||||||
resbuf : array[0..7] of byte;
|
resbuf : array[0..7] of byte;
|
||||||
@ -773,23 +772,26 @@ var dh : pointer;
|
|||||||
begin
|
begin
|
||||||
with cursor as TIBcursor do
|
with cursor as TIBcursor do
|
||||||
begin
|
begin
|
||||||
dh := GetHandle;
|
DatabaseHandle := GetHandle;
|
||||||
if isc_dsql_allocate_statement(@Status[0], @dh, @Statement) <> 0 then
|
TransactionHandle := aTransaction.Handle;
|
||||||
|
|
||||||
|
if isc_dsql_allocate_statement(@Status[0], @DatabaseHandle, @StatementHandle) <> 0 then
|
||||||
CheckError('PrepareStatement', Status);
|
CheckError('PrepareStatement', Status);
|
||||||
tr := aTransaction.Handle;
|
|
||||||
|
|
||||||
if assigned(AParams) and (AParams.count > 0) then
|
if assigned(AParams) and (AParams.count > 0) then
|
||||||
begin
|
begin
|
||||||
buf := AParams.ParseSQL(buf,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase,paramBinding);
|
buf := AParams.ParseSQL(buf,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase,paramBinding);
|
||||||
if LogEvent(detActualSQL) then
|
if LogEvent(detActualSQL) then
|
||||||
Log(detActualSQL,Buf);
|
Log(detActualSQL,Buf);
|
||||||
end;
|
end;
|
||||||
if isc_dsql_prepare(@Status[0], @tr, @Statement, 0, @Buf[1], Dialect, nil) <> 0 then
|
|
||||||
|
if isc_dsql_prepare(@Status[0], @TransactionHandle, @StatementHandle, 0, @Buf[1], Dialect, nil) <> 0 then
|
||||||
CheckError('PrepareStatement', Status);
|
CheckError('PrepareStatement', Status);
|
||||||
|
|
||||||
if assigned(AParams) and (AParams.count > 0) then
|
if assigned(AParams) and (AParams.count > 0) then
|
||||||
begin
|
begin
|
||||||
AllocSQLDA(in_SQLDA,Length(ParamBinding));
|
AllocSQLDA(in_SQLDA,Length(ParamBinding));
|
||||||
if isc_dsql_describe_bind(@Status[0], @Statement, 1, in_SQLDA) <> 0 then
|
if isc_dsql_describe_bind(@Status[0], @StatementHandle, 1, in_SQLDA) <> 0 then
|
||||||
CheckError('PrepareStatement', Status);
|
CheckError('PrepareStatement', Status);
|
||||||
if in_SQLDA^.SQLD > in_SQLDA^.SQLN then
|
if in_SQLDA^.SQLD > in_SQLDA^.SQLN then
|
||||||
DatabaseError(SParameterCountIncorrect,self);
|
DatabaseError(SParameterCountIncorrect,self);
|
||||||
@ -815,7 +817,7 @@ begin
|
|||||||
|
|
||||||
// Get the statement type from firebird/interbase
|
// Get the statement type from firebird/interbase
|
||||||
info_request := chr(isc_info_sql_stmt_type);
|
info_request := chr(isc_info_sql_stmt_type);
|
||||||
if isc_dsql_sql_info(@Status[0],@Statement,Length(info_request), @info_request[1],sizeof(resbuf),@resbuf) <> 0 then
|
if isc_dsql_sql_info(@Status[0],@StatementHandle,Length(info_request), @info_request[1],sizeof(resbuf),@resbuf) <> 0 then
|
||||||
CheckError('PrepareStatement', Status);
|
CheckError('PrepareStatement', Status);
|
||||||
assert(resbuf[0]=isc_info_sql_stmt_type);
|
assert(resbuf[0]=isc_info_sql_stmt_type);
|
||||||
BlockSize:=isc_vax_integer(@resbuf[1],2);
|
BlockSize:=isc_vax_integer(@resbuf[1],2);
|
||||||
@ -835,12 +837,12 @@ begin
|
|||||||
|
|
||||||
if FSelectable then
|
if FSelectable then
|
||||||
begin
|
begin
|
||||||
if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
|
if isc_dsql_describe(@Status[0], @StatementHandle, 1, SQLDA) <> 0 then
|
||||||
CheckError('PrepareSelect', Status);
|
CheckError('PrepareSelect', Status);
|
||||||
if SQLDA^.SQLD > SQLDA^.SQLN then
|
if SQLDA^.SQLD > SQLDA^.SQLN then
|
||||||
begin
|
begin
|
||||||
AllocSQLDA(SQLDA,SQLDA^.SQLD);
|
AllocSQLDA(SQLDA,SQLDA^.SQLD);
|
||||||
if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
|
if isc_dsql_describe(@Status[0], @StatementHandle, 1, SQLDA) <> 0 then
|
||||||
CheckError('PrepareSelect', Status);
|
CheckError('PrepareSelect', Status);
|
||||||
end;
|
end;
|
||||||
FSelectable := SQLDA^.SQLD > 0;
|
FSelectable := SQLDA^.SQLD > 0;
|
||||||
@ -864,11 +866,11 @@ procedure TIBConnection.UnPrepareStatement(cursor : TSQLCursor);
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
with cursor as TIBcursor do
|
with cursor as TIBcursor do
|
||||||
if assigned(Statement) Then
|
if assigned(StatementHandle) Then
|
||||||
begin
|
begin
|
||||||
if isc_dsql_free_statement(@Status[0], @Statement, DSQL_Drop) <> 0 then
|
if isc_dsql_free_statement(@Status[0], @StatementHandle, DSQL_Drop) <> 0 then
|
||||||
CheckError('FreeStatement', Status);
|
CheckError('FreeStatement', Status);
|
||||||
Statement := nil;
|
StatementHandle := nil;
|
||||||
FPrepared := False;
|
FPrepared := False;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -934,7 +936,7 @@ begin
|
|||||||
out_SQLDA := SQLDA
|
out_SQLDA := SQLDA
|
||||||
else
|
else
|
||||||
out_SQLDA := nil;
|
out_SQLDA := nil;
|
||||||
if isc_dsql_execute2(@Status[0], @tr, @Statement, 1, in_SQLDA, out_SQLDA) <> 0 then
|
if isc_dsql_execute2(@Status[0], @tr, @StatementHandle, 1, in_SQLDA, out_SQLDA) <> 0 then
|
||||||
CheckError('Execute', Status);
|
CheckError('Execute', Status);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -975,7 +977,7 @@ end;
|
|||||||
|
|
||||||
function TIBConnection.GetHandle: pointer;
|
function TIBConnection.GetHandle: pointer;
|
||||||
begin
|
begin
|
||||||
Result := FSQLDatabaseHandle;
|
Result := FDatabaseHandle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIBConnection.Fetch(cursor : TSQLCursor) : boolean;
|
function TIBConnection.Fetch(cursor : TSQLCursor) : boolean;
|
||||||
@ -995,7 +997,7 @@ begin
|
|||||||
SQLDA^.SQLD := 0; //hack: mark after first fetch
|
SQLDA^.SQLD := 0; //hack: mark after first fetch
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
retcode := isc_dsql_fetch(@Status[0], @Statement, 1, SQLDA);
|
retcode := isc_dsql_fetch(@Status[0], @StatementHandle, 1, SQLDA);
|
||||||
if (retcode <> 0) and (retcode <> 100) then
|
if (retcode <> 0) and (retcode <> 100) then
|
||||||
CheckError('Fetch', Status);
|
CheckError('Fetch', Status);
|
||||||
end;
|
end;
|
||||||
@ -1019,7 +1021,7 @@ procedure TIBConnection.SetParameters(cursor : TSQLCursor; aTransation : TSQLTra
|
|||||||
|
|
||||||
var
|
var
|
||||||
// This should be a pointer, because the ORIGINAL variables must be modified.
|
// This should be a pointer, because the ORIGINAL variables must be modified.
|
||||||
VSQLVar : ^XSQLVAR;
|
VSQLVar : PXSQLVAR;
|
||||||
AParam : TParam;
|
AParam : TParam;
|
||||||
s : rawbytestring;
|
s : rawbytestring;
|
||||||
i : integer;
|
i : integer;
|
||||||
@ -1038,7 +1040,7 @@ var
|
|||||||
begin
|
begin
|
||||||
TransactionHandle := aTransation.Handle;
|
TransactionHandle := aTransation.Handle;
|
||||||
BlobHandle := FB_API_NULLHANDLE;
|
BlobHandle := FB_API_NULLHANDLE;
|
||||||
if isc_create_blob(@FStatus[0], @FSQLDatabaseHandle, @TransactionHandle, @BlobHandle, @BlobId) <> 0 then
|
if isc_create_blob(@FStatus[0], @FDatabaseHandle, @TransactionHandle, @BlobHandle, @BlobId) <> 0 then
|
||||||
CheckError('TIBConnection.CreateBlobStream', FStatus);
|
CheckError('TIBConnection.CreateBlobStream', FStatus);
|
||||||
|
|
||||||
if VSQLVar^.sqlsubtype = isc_blob_text then
|
if VSQLVar^.sqlsubtype = isc_blob_text then
|
||||||
@ -1167,7 +1169,7 @@ begin
|
|||||||
{$pop}
|
{$pop}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIBConnection.LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer; out CreateBlob : boolean) : boolean;
|
function TIBConnection.LoadField(cursor : TSQLCursor; FieldDef : TFieldDef; buffer : pointer; out CreateBlob : boolean) : boolean;
|
||||||
|
|
||||||
var
|
var
|
||||||
VSQLVar : PXSQLVAR;
|
VSQLVar : PXSQLVAR;
|
||||||
@ -1631,7 +1633,7 @@ begin
|
|||||||
TransactionHandle := Atransaction.Handle;
|
TransactionHandle := Atransaction.Handle;
|
||||||
blobHandle := FB_API_NULLHANDLE;
|
blobHandle := FB_API_NULLHANDLE;
|
||||||
|
|
||||||
if isc_open_blob(@FStatus[0], @FSQLDatabaseHandle, @TransactionHandle, @blobHandle, blobId) <> 0 then
|
if isc_open_blob(@FStatus[0], @FDatabaseHandle, @TransactionHandle, @blobHandle, blobId) <> 0 then
|
||||||
CheckError('TIBConnection.CreateBlobStream', FStatus);
|
CheckError('TIBConnection.CreateBlobStream', FStatus);
|
||||||
|
|
||||||
//For performance, read as much as we can, regardless of any segment size set in database.
|
//For performance, read as much as we can, regardless of any segment size set in database.
|
||||||
@ -1674,10 +1676,10 @@ begin
|
|||||||
InsertedRows:=-1;
|
InsertedRows:=-1;
|
||||||
|
|
||||||
if assigned(cursor) then with cursor as TIBCursor do
|
if assigned(cursor) then with cursor as TIBCursor do
|
||||||
if assigned(statement) then
|
if assigned(StatementHandle) then
|
||||||
begin
|
begin
|
||||||
info_request := chr(isc_info_sql_records);
|
info_request := chr(isc_info_sql_records);
|
||||||
if isc_dsql_sql_info(@Status[0],@Statement,Length(info_request), @info_request[1],sizeof(resbuf),@resbuf) <> 0 then
|
if isc_dsql_sql_info(@Status[0], @StatementHandle, Length(info_request), @info_request[1],sizeof(resbuf),@resbuf) <> 0 then
|
||||||
CheckError('RowsAffected', Status);
|
CheckError('RowsAffected', Status);
|
||||||
|
|
||||||
i := 0;
|
i := 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user