mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-01 04:10:40 +02:00
* Fixed prepare for select statements
git-svn-id: trunk@11511 -
This commit is contained in:
parent
c42838a02e
commit
d39c352d92
@ -533,7 +533,6 @@ begin
|
||||
|
||||
if isc_dsql_prepare(@Status[0], @tr, @Statement, 0, @Buf[1], Dialect, nil) <> 0 then
|
||||
CheckError('PrepareStatement', Status);
|
||||
FPrepared := True;
|
||||
if assigned(AParams) and (AParams.count > 0) then
|
||||
begin
|
||||
AllocSQLDA(in_SQLDA,Length(ParamBinding));
|
||||
@ -556,7 +555,6 @@ begin
|
||||
AllocSQLDA(in_SQLDA,0);
|
||||
if FStatementType = stselect then
|
||||
begin
|
||||
FPrepared := False;
|
||||
if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
|
||||
CheckError('PrepareSelect', Status);
|
||||
if SQLDA^.SQLD > SQLDA^.SQLN then
|
||||
@ -576,6 +574,7 @@ begin
|
||||
end;
|
||||
{$R+}
|
||||
end;
|
||||
FPrepared := True;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -212,7 +212,7 @@ type
|
||||
FUpdateQry,
|
||||
FDeleteQry,
|
||||
FInsertQry : TCustomSQLQuery;
|
||||
|
||||
FOpenDidPrepare : Boolean;
|
||||
procedure FreeFldBuffers;
|
||||
function GetServerIndexDefs: TServerIndexDefs;
|
||||
function GetStatementType : TStatementType;
|
||||
@ -993,7 +993,11 @@ procedure TCustomSQLQuery.InternalClose;
|
||||
begin
|
||||
if StatementType = stSelect then FreeFldBuffers;
|
||||
// Database and FCursor could be nil, for example if the database is not assigned, and .open is called
|
||||
if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then TSQLConnection(database).UnPrepareStatement(FCursor);
|
||||
if (FOpenDidPrepare) and (assigned(database)) and (assigned(FCursor)) then
|
||||
begin
|
||||
FOpenDidPrepare:=False;
|
||||
TSQLConnection(database).UnPrepareStatement(FCursor);
|
||||
end;
|
||||
if DefaultFields then
|
||||
DestroyFields;
|
||||
FIsEOF := False;
|
||||
@ -1176,7 +1180,9 @@ var tel, fieldc : integer;
|
||||
IndexFields : TStrings;
|
||||
begin
|
||||
try
|
||||
Prepare;
|
||||
FOpenDidPrepare:=Not Prepared;
|
||||
If FOpenDidPrepare then
|
||||
Prepare;
|
||||
if FCursor.FStatementType in [stSelect] then
|
||||
begin
|
||||
Execute;
|
||||
@ -1230,14 +1236,21 @@ end;
|
||||
// public part
|
||||
|
||||
procedure TCustomSQLQuery.ExecSQL;
|
||||
|
||||
Var
|
||||
ExecDidPrepare : Boolean;
|
||||
|
||||
begin
|
||||
try
|
||||
Prepare;
|
||||
ExecDidPrepare:=Not IsPrepared;
|
||||
If ExecDidPrepare then
|
||||
Prepare;
|
||||
Execute;
|
||||
finally
|
||||
// FCursor has to be assigned, or else the prepare went wrong before PrepareStatment was
|
||||
// called, so UnPrepareStatement shoudn't be called either
|
||||
if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then TSQLConnection(database).UnPrepareStatement(Fcursor);
|
||||
if (ExecDidPrepare) and (assigned(database)) and (assigned(FCursor)) then
|
||||
TSQLConnection(database).UnPrepareStatement(Fcursor);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user