Skip to content

Commit

Permalink
Stop "Transaction not active" error for StoredProc component when dat…
Browse files Browse the repository at this point in the history
…abase not open
  • Loading branch information
todaysoftware committed Jun 9, 2024
1 parent 0ec70ce commit 300c454
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions FIBQuery.pas
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ TFIBQuery = class(TComponent,ISQLObject,IFIBQuery)
procedure CheckClosed(const OpName:Ansistring);// raise error if query is not closed.
procedure CheckOpen(const OpName:Ansistring); // raise error if query is not open.
procedure CheckValidStatement; // raise error if statement is invalid.
procedure Close; // close the query.
procedure Close; virtual; // close the query.
function Current: TFIBXSQLDA;
procedure ExecQuery; virtual; // ExecQuery the query.
procedure ExecuteImmediate;
Expand All @@ -535,7 +535,7 @@ TFIBQuery = class(TComponent,ISQLObject,IFIBQuery)
{$ENDIF}
procedure FreeHandle;
function Next: TFIBXSQLDA;
procedure Prepare; // Prepare the query.
procedure Prepare; virtual; // Prepare the query.

function FieldByName(const FieldName: string): TFIBXSQLVAR;
function FindField(const FieldName: string): TFIBXSQLVAR;
Expand Down
44 changes: 27 additions & 17 deletions pFIBStoredProc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ TpFIBStoredProc = class(TpFIBQuery)
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Prepare; override;
procedure ExecQuery; override;
function GetParamDefValue(ParamNo:integer):string; overload;
function GetParamDefValue(const ParamName:string):string; overload;

Expand All @@ -62,28 +64,13 @@ implementation
'ORDER BY PP.RDB$PARAMETER_NUMBER';

procedure TpFIBStoredProc.SetStoredProc(const Value: string);
var ProcName:string;
begin
if (Value <> FStoredProc) then
begin
FStoredProc := Value;
if not (csReading in ComponentState) then
begin
// FBase.CheckDatabase;
if Assigned(Database) then
if IsBlank(Value) then
SQL.Clear
else
begin
ProcName:=EasyFormatIdentifier(Database.SQLDialect, FStoredProc,
Database.EasyFormatsStr
);
SQL.Text :=
ListSPInfo.GetExecProcTxt(Database,
ProcName
,csDesigning in ComponentState
);
end;
SQL.Clear;
end;
end;
end;
Expand Down Expand Up @@ -205,5 +192,28 @@ procedure TpFIBStoredProc.SetDatabase(Value: TFIBDatabase);
end;
end;

end.
procedure TpFIBStoredProc.ExecQuery;
begin
if not Prepared then
Prepare;
inherited;
end;

procedure TpFIBStoredProc.Prepare;
var ProcName:string;
begin
if (SQL.Count = 0) and not IsBlank(FStoredProc) then
begin
ProcName:=EasyFormatIdentifier(Database.SQLDialect, FStoredProc,
Database.EasyFormatsStr
);
SQL.Text :=
ListSPInfo.GetExecProcTxt(Database,
ProcName
,csDesigning in ComponentState
);
end;
inherited;
end;

end.

0 comments on commit 300c454

Please sign in to comment.