mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 00:08:12 +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)
|
||||
protected
|
||||
Status : array [0..19] of ISC_STATUS;
|
||||
Statement : pointer;
|
||||
TransactionHandle : pointer;
|
||||
StatementHandle : pointer;
|
||||
SQLDA : PXSQLDA;
|
||||
in_SQLDA : PXSQLDA;
|
||||
ParamBinding : array of integer;
|
||||
@ -55,7 +56,7 @@ type
|
||||
TIBConnection = class (TSQLConnection)
|
||||
private
|
||||
FCheckTransactionParams: Boolean;
|
||||
FSQLDatabaseHandle : pointer;
|
||||
FDatabaseHandle : pointer;
|
||||
FStatus : array [0..19] of ISC_STATUS;
|
||||
FDatabaseInfo : TDatabaseInfo;
|
||||
FDialect : integer;
|
||||
@ -366,7 +367,7 @@ begin
|
||||
|
||||
ConnectFB;
|
||||
|
||||
if isc_drop_database(@FStatus[0], @FSQLDatabaseHandle) <> 0 then
|
||||
if isc_drop_database(@FStatus[0], @FDatabaseHandle) <> 0 then
|
||||
CheckError('DropDB', FStatus);
|
||||
|
||||
{$IfDef LinkDynamically}
|
||||
@ -431,11 +432,11 @@ begin
|
||||
if not Connected then
|
||||
begin
|
||||
ResetDatabaseInfo;
|
||||
FSQLDatabaseHandle := nil;
|
||||
FDatabaseHandle := nil;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if isc_detach_database(@FStatus[0], @FSQLDatabaseHandle) <> 0 then
|
||||
if isc_detach_database(@FStatus[0], @FDatabaseHandle) <> 0 then
|
||||
CheckError('Close', FStatus);
|
||||
{$IfDef LinkDynamically}
|
||||
ReleaseIBase60;
|
||||
@ -498,7 +499,7 @@ begin
|
||||
ReqBuf[1] := isc_info_version;
|
||||
ReqBuf[2] := isc_info_db_sql_dialect;
|
||||
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
|
||||
CheckError('CacheServerInfo', FStatus);
|
||||
x := 0;
|
||||
@ -623,12 +624,11 @@ begin
|
||||
if Length(CharSet) > 0 then
|
||||
DPB := DPB + Chr(isc_dpb_lc_ctype) + Chr(Length(CharSet)) + CharSet;
|
||||
|
||||
FSQLDatabaseHandle := nil;
|
||||
FDatabaseHandle := nil;
|
||||
if HostName <> '' then ADatabaseName := HostName+':'+DatabaseName
|
||||
else ADatabaseName := DatabaseName;
|
||||
if isc_attach_database(@FStatus[0], Length(ADatabaseName), @ADatabaseName[1],
|
||||
@FSQLDatabaseHandle,
|
||||
Length(DPB), @DPB[1]) <> 0 then
|
||||
@FDatabaseHandle, Length(DPB), @DPB[1]) <> 0 then
|
||||
CheckError('DoInternalConnect', FStatus);
|
||||
end;
|
||||
|
||||
@ -737,7 +737,7 @@ var curs : TIBCursor;
|
||||
begin
|
||||
curs := TIBCursor.create;
|
||||
curs.sqlda := nil;
|
||||
curs.statement := nil;
|
||||
curs.StatementHandle := nil;
|
||||
curs.FPrepared := False;
|
||||
AllocSQLDA(curs.SQLDA,0);
|
||||
result := curs;
|
||||
@ -762,8 +762,7 @@ end;
|
||||
|
||||
procedure TIBConnection.PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams);
|
||||
|
||||
var dh : pointer;
|
||||
tr : pointer;
|
||||
var DatabaseHandle : pointer;
|
||||
x : Smallint;
|
||||
info_request : string;
|
||||
resbuf : array[0..7] of byte;
|
||||
@ -773,23 +772,26 @@ var dh : pointer;
|
||||
begin
|
||||
with cursor as TIBcursor do
|
||||
begin
|
||||
dh := GetHandle;
|
||||
if isc_dsql_allocate_statement(@Status[0], @dh, @Statement) <> 0 then
|
||||
DatabaseHandle := GetHandle;
|
||||
TransactionHandle := aTransaction.Handle;
|
||||
|
||||
if isc_dsql_allocate_statement(@Status[0], @DatabaseHandle, @StatementHandle) <> 0 then
|
||||
CheckError('PrepareStatement', Status);
|
||||
tr := aTransaction.Handle;
|
||||
|
||||
|
||||
if assigned(AParams) and (AParams.count > 0) then
|
||||
begin
|
||||
buf := AParams.ParseSQL(buf,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase,paramBinding);
|
||||
if LogEvent(detActualSQL) then
|
||||
Log(detActualSQL,Buf);
|
||||
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);
|
||||
|
||||
if assigned(AParams) and (AParams.count > 0) then
|
||||
begin
|
||||
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);
|
||||
if in_SQLDA^.SQLD > in_SQLDA^.SQLN then
|
||||
DatabaseError(SParameterCountIncorrect,self);
|
||||
@ -815,7 +817,7 @@ begin
|
||||
|
||||
// Get the statement type from firebird/interbase
|
||||
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);
|
||||
assert(resbuf[0]=isc_info_sql_stmt_type);
|
||||
BlockSize:=isc_vax_integer(@resbuf[1],2);
|
||||
@ -835,12 +837,12 @@ begin
|
||||
|
||||
if FSelectable then
|
||||
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);
|
||||
if SQLDA^.SQLD > SQLDA^.SQLN then
|
||||
begin
|
||||
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);
|
||||
end;
|
||||
FSelectable := SQLDA^.SQLD > 0;
|
||||
@ -864,11 +866,11 @@ procedure TIBConnection.UnPrepareStatement(cursor : TSQLCursor);
|
||||
|
||||
begin
|
||||
with cursor as TIBcursor do
|
||||
if assigned(Statement) Then
|
||||
if assigned(StatementHandle) Then
|
||||
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);
|
||||
Statement := nil;
|
||||
StatementHandle := nil;
|
||||
FPrepared := False;
|
||||
end;
|
||||
end;
|
||||
@ -934,7 +936,7 @@ begin
|
||||
out_SQLDA := SQLDA
|
||||
else
|
||||
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);
|
||||
end;
|
||||
end;
|
||||
@ -975,7 +977,7 @@ end;
|
||||
|
||||
function TIBConnection.GetHandle: pointer;
|
||||
begin
|
||||
Result := FSQLDatabaseHandle;
|
||||
Result := FDatabaseHandle;
|
||||
end;
|
||||
|
||||
function TIBConnection.Fetch(cursor : TSQLCursor) : boolean;
|
||||
@ -995,7 +997,7 @@ begin
|
||||
SQLDA^.SQLD := 0; //hack: mark after first fetch
|
||||
end
|
||||
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
|
||||
CheckError('Fetch', Status);
|
||||
end;
|
||||
@ -1019,7 +1021,7 @@ procedure TIBConnection.SetParameters(cursor : TSQLCursor; aTransation : TSQLTra
|
||||
|
||||
var
|
||||
// This should be a pointer, because the ORIGINAL variables must be modified.
|
||||
VSQLVar : ^XSQLVAR;
|
||||
VSQLVar : PXSQLVAR;
|
||||
AParam : TParam;
|
||||
s : rawbytestring;
|
||||
i : integer;
|
||||
@ -1038,7 +1040,7 @@ var
|
||||
begin
|
||||
TransactionHandle := aTransation.Handle;
|
||||
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);
|
||||
|
||||
if VSQLVar^.sqlsubtype = isc_blob_text then
|
||||
@ -1167,7 +1169,7 @@ begin
|
||||
{$pop}
|
||||
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
|
||||
VSQLVar : PXSQLVAR;
|
||||
@ -1631,7 +1633,7 @@ begin
|
||||
TransactionHandle := Atransaction.Handle;
|
||||
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);
|
||||
|
||||
//For performance, read as much as we can, regardless of any segment size set in database.
|
||||
@ -1674,10 +1676,10 @@ begin
|
||||
InsertedRows:=-1;
|
||||
|
||||
if assigned(cursor) then with cursor as TIBCursor do
|
||||
if assigned(statement) then
|
||||
if assigned(StatementHandle) then
|
||||
begin
|
||||
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);
|
||||
|
||||
i := 0;
|
||||
|
Loading…
Reference in New Issue
Block a user