ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/fbintf/client/FBStatement.pas
(Generate patch)

Comparing:
ibx/trunk/fbintf/client/FBStatement.pas (file contents), Revision 345 by tony, Mon Aug 23 14:22:29 2021 UTC vs.
ibx/branches/journaling/fbintf/client/FBStatement.pas (file contents), Revision 363 by tony, Tue Dec 7 13:30:05 2021 UTC

# Line 59 | Line 59 | type
59    protected
60      FTransactionIntf: ITransaction;
61      FExecTransactionIntf: ITransaction;
62 +    FStaleReferenceChecks: boolean;
63      FSQLStatementType: TIBSQLStatementTypes;         { Select, update, delete, insert, create, alter, etc...}
64      FSQLDialect: integer;
65      FOpen: boolean;
# Line 81 | Line 82 | type
82      procedure CheckChangeBatchRowLimit; virtual;
83      procedure CheckHandle; virtual; abstract;
84      procedure CheckTransaction(aTransaction: ITransaction);
85 +    procedure DoJournaling;
86 +    function GetJournalIntf: IJournallingHook;
87 +    function GetStatementIntf: IStatement; virtual; abstract;
88      procedure GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults); overload; virtual; abstract;
89 <    procedure InternalPrepare;  virtual; abstract;
89 >    procedure InternalPrepare(CursorName: AnsiString='');  virtual; abstract;
90      function InternalExecute(Transaction: ITransaction): IResults;  virtual; abstract;
91 <    function InternalOpenCursor(aTransaction: ITransaction): IResultSet;   virtual; abstract;
91 >    function InternalOpenCursor(aTransaction: ITransaction; Scrollable: boolean): IResultSet;   virtual; abstract;
92      procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); virtual; abstract;
93      procedure FreeHandle;  virtual; abstract;
94      procedure InternalClose(Force: boolean); virtual; abstract;
# Line 111 | Line 115 | type
115      function GetSQLText: AnsiString;
116      function GetProcessedSQLText: AnsiString;
117      function GetSQLDialect: integer;
118 +    function GetFlags: TStatementFlags; virtual;
119  
120      {GetDSQLInfo only supports isc_info_sql_stmt_type, isc_info_sql_get_plan, isc_info_sql_records}
121 <    procedure Prepare(aTransaction: ITransaction=nil); virtual;
121 >    procedure Prepare(aTransaction: ITransaction=nil);  overload;
122 >    procedure Prepare(CursorName: AnsiString; aTransaction: ITransaction=nil); overload; virtual;
123      function Execute(aTransaction: ITransaction=nil): IResults;
124 <    function OpenCursor(aTransaction: ITransaction=nil): IResultSet;
124 >    function OpenCursor(aTransaction: ITransaction=nil): IResultSet; overload;
125 >    function OpenCursor(Scrollable: boolean; aTransaction: ITransaction=nil): IResultSet; overload;
126      function CreateBlob(paramName: AnsiString): IBlob; overload;
127      function CreateBlob(index: integer): IBlob; overload;
128      function CreateBlob(column: TColumnMetaData): IBlob; overload; virtual; abstract;
# Line 138 | Line 145 | type
145      function GetBatchCompletion: IBatchCompletion; virtual;
146      function GetBatchRowLimit: integer;
147      procedure SetBatchRowLimit(aLimit: integer);
148 +    {Stale Reference Check}
149 +    procedure SetStaleReferenceChecks(Enable:boolean); {default true}
150 +    function GetStaleReferenceChecks: boolean;
151    public
152      property ChangeSeqNo: integer read FChangeSeqNo;
153      property SQLParams: ISQLParams read GetSQLParams;
# Line 164 | Line 174 | begin
174      IBError(ibxeNotInTransaction,[]);
175   end;
176  
177 + procedure TFBStatement.DoJournaling;
178 +  function doGetRowsAffected: integer;
179 +  var a,i,u,d: integer;
180 +  begin
181 +    GetRowsAffected(a,i,u,d);
182 +    Result := i + u + d;
183 +  end;
184 +
185 + var RowsAffected: integer;
186 + begin
187 +  RowsAffected := doGetRowsAffected;
188 +  with GetAttachment do
189 +    if JournalingActive and
190 +      (((joReadOnlyQueries in GetJournalOptions) and (RowsAffected = 0)) or
191 +      ((joModifyQueries in GetJournalOptions) and (RowsAffected > 0))) then
192 +      GetJournalIntf.ExecQuery(GetStatementIntf);
193 + end;
194 +
195 + function TFBStatement.GetJournalIntf: IJournallingHook;
196 + begin
197 +  GetAttachment.QueryInterface(IJournallingHook,Result)
198 + end;
199 +
200   function TFBStatement.TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64;
201   begin
202    Result := TimeStamp.Time + Int64(timestamp.date)*msecsperday;
# Line 179 | Line 212 | begin
212    FSQLDialect := SQLDialect;
213    FSQL := sql;
214    FBatchRowLimit := DefaultBatchRowLimit;
215 +  FStaleReferenceChecks := true;
216   end;
217  
218   constructor TFBStatement.CreateWithParameterNames(Attachment: IAttachment;
# Line 282 | Line 316 | end;
316  
317   function TFBStatement.GetProcessedSQLText: AnsiString;
318   begin
319 <  if FProcessedSQL = '' then
320 <    ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL);
321 <  Result := FProcessedSQL
319 >  if not FHasParamNames then
320 >    Result := FSQL
321 >  else
322 >  begin
323 >    if FProcessedSQL = '' then
324 >      ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL);
325 >    Result := FProcessedSQL;
326 >  end;
327   end;
328  
329   function TFBStatement.GetSQLDialect: integer;
# Line 292 | Line 331 | begin
331    Result := FSQLDialect;
332   end;
333  
334 + function TFBStatement.GetFlags: TStatementFlags;
335 + begin
336 +  Result := [];
337 + end;
338 +
339   procedure TFBStatement.Prepare(aTransaction: ITransaction);
340   begin
341 +  Prepare('',aTransaction);
342 + end;
343 +
344 + procedure TFBStatement.Prepare(CursorName: AnsiString;
345 +  aTransaction: ITransaction);
346 + begin
347    if FPrepared then FreeHandle;
348    if aTransaction <> nil then
349    begin
# Line 301 | Line 351 | begin
351      FTransactionIntf := aTransaction;
352      AddMonitor(FTransactionIntf as TFBTransaction);
353    end;
354 <  InternalPrepare;
354 >  InternalPrepare(CursorName);
355   end;
356  
357   function TFBStatement.Execute(aTransaction: ITransaction): IResults;
# Line 310 | Line 360 | begin
360      Result :=  InternalExecute(FTransactionIntf)
361    else
362      Result := InternalExecute(aTransaction);
363 +  DoJournaling;
364   end;
365  
366   procedure TFBStatement.AddToBatch;
# Line 344 | Line 395 | begin
395    FBatchRowLimit := aLimit;
396   end;
397  
398 + procedure TFBStatement.SetStaleReferenceChecks(Enable: boolean);
399 + begin
400 +  FStaleReferenceChecks := Enable;
401 + end;
402 +
403 + function TFBStatement.GetStaleReferenceChecks: boolean;
404 + begin
405 +  Result := FStaleReferenceChecks;
406 + end;
407 +
408   function TFBStatement.OpenCursor(aTransaction: ITransaction): IResultSet;
409   begin
410 +  Result := OpenCursor(false,aTransaction);
411 + end;
412 +
413 + function TFBStatement.OpenCursor(Scrollable: boolean; aTransaction: ITransaction
414 +  ): IResultSet;
415 + begin
416    Close;
417    if aTransaction = nil then
418 <    Result := InternalOpenCursor(FTransactionIntf)
418 >    Result := InternalOpenCursor(FTransactionIntf,Scrollable)
419    else
420 <    Result := InternalOpenCursor(aTransaction);
420 >    Result := InternalOpenCursor(aTransaction,Scrollable);
421 >  DoJournaling;
422   end;
423  
424   function TFBStatement.CreateBlob(paramName: AnsiString): IBlob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines