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 209 by tony, Wed Mar 14 12:48:51 2018 UTC vs.
Revision 347 by tony, Mon Sep 20 22:08:20 2021 UTC

# Line 44 | Line 44 | uses
44    Classes, SysUtils,  IB,  FBClientAPI, FBSQLData, FBOutputBlock, FBActivityMonitor,
45    FBTransaction;
46  
47 + const
48 +  DefaultBatchRowLimit = 1000;
49 +
50   type
51    TPerfStatistics = array[psCurrentMemory..psFetches] of Int64;
52  
53    { TFBStatement }
54  
55 <  TFBStatement = class(TActivityReporter)
55 >  TFBStatement = class(TActivityReporter,ITransactionUser)
56    private
57      FAttachmentIntf: IAttachment;
58 +    FFirebirdClientAPI: TFBClientAPI;
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 72 | Line 77 | type
77      FStatisticsAvailable: boolean;
78      FBeforeStats: TPerfStatistics;
79      FAfterStats: TPerfStatistics;
80 +    FCaseSensitiveParams: boolean;
81 +    FBatchRowLimit: integer;
82 +    procedure CheckChangeBatchRowLimit; virtual;
83      procedure CheckHandle; virtual; abstract;
84      procedure CheckTransaction(aTransaction: ITransaction);
85      procedure GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults); overload; virtual; abstract;
86      procedure InternalPrepare;  virtual; abstract;
87 <    function InternalExecute(aTransaction: ITransaction): IResults;  virtual; abstract;
87 >    function InternalExecute(Transaction: ITransaction): IResults;  virtual; abstract;
88      function InternalOpenCursor(aTransaction: ITransaction): IResultSet;   virtual; abstract;
89 +    procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); virtual; abstract;
90      procedure FreeHandle;  virtual; abstract;
91      procedure InternalClose(Force: boolean); virtual; abstract;
92      function TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64;
# Line 85 | Line 94 | type
94      constructor Create(Attachment: IAttachment; Transaction: ITransaction;
95        sql: AnsiString; SQLDialect: integer);
96      constructor CreateWithParameterNames(Attachment: IAttachment; Transaction: ITransaction;
97 <      sql: AnsiString;  SQLDialect: integer; GenerateParamNames: boolean =false);
97 >      sql: AnsiString;  SQLDialect: integer; GenerateParamNames: boolean =false;
98 >      CaseSensitiveParams: boolean = false);
99      destructor Destroy; override;
100      procedure Close;
101      procedure TransactionEnding(aTransaction: ITransaction; Force: boolean);
102      property SQLDialect: integer read FSQLDialect;
103 +    property FirebirdClientAPI: TFBClientAPI read FFirebirdClientAPI;
104  
105    public
106      function GetSQLParams: ISQLParams; virtual; abstract;
# Line 97 | Line 108 | type
108      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount,
109        DeleteCount: integer): boolean;
110      function GetSQLStatementType: TIBSQLStatementTypes;
111 +    function GetSQLStatementTypeName: AnsiString;
112      function GetSQLText: AnsiString;
113 +    function GetProcessedSQLText: AnsiString;
114      function GetSQLDialect: integer;
115  
116      {GetDSQLInfo only supports isc_info_sql_stmt_type, isc_info_sql_get_plan, isc_info_sql_records}
# Line 116 | Line 129 | type
129      procedure SetRetainInterfaces(aValue: boolean); virtual;
130      procedure EnableStatistics(aValue: boolean);
131      function GetPerfStatistics(var stats: TPerfCounters): boolean;
132 +    function IsInBatchMode: boolean; virtual;
133 +    function HasBatchMode: boolean; virtual;
134 +  public
135 +    {IBatch support}
136 +    procedure AddToBatch; virtual;
137 +    function ExecuteBatch(aTransaction: ITransaction): IBatchCompletion; virtual;
138 +    procedure CancelBatch; virtual;
139 +    function GetBatchCompletion: IBatchCompletion; virtual;
140 +    function GetBatchRowLimit: integer;
141 +    procedure SetBatchRowLimit(aLimit: integer);
142 +    {Stale Reference Check}
143 +    procedure SetStaleReferenceChecks(Enable:boolean); {default true}
144 +    function GetStaleReferenceChecks: boolean;
145 +  public
146      property ChangeSeqNo: integer read FChangeSeqNo;
147      property SQLParams: ISQLParams read GetSQLParams;
148      property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
# Line 127 | Line 154 | uses FBMessages;
154  
155   { TFBStatement }
156  
157 + procedure TFBStatement.CheckChangeBatchRowLimit;
158 + begin
159 +  //Do Nothing
160 + end;
161 +
162   procedure TFBStatement.CheckTransaction(aTransaction: ITransaction);
163   begin
164    if (aTransaction = nil) then
# Line 147 | Line 179 | begin
179    inherited Create(Transaction as TFBTransaction,2);
180    FAttachmentIntf := Attachment;
181    FTransactionIntf := Transaction;
182 +  FFirebirdClientAPI := Attachment.getFirebirdAPI as TFBClientAPI;
183    FSQLDialect := SQLDialect;
184    FSQL := sql;
185 +  FBatchRowLimit := DefaultBatchRowLimit;
186 +  FStaleReferenceChecks := true;
187   end;
188  
189   constructor TFBStatement.CreateWithParameterNames(Attachment: IAttachment;
190    Transaction: ITransaction; sql: AnsiString; SQLDialect: integer;
191 <  GenerateParamNames: boolean);
191 >  GenerateParamNames: boolean; CaseSensitiveParams: boolean);
192   begin
193    FHasParamNames := true;
194    FGenerateParamNames := GenerateParamNames;
195 +  FCaseSensitiveParams := CaseSensitiveParams;
196    Create(Attachment,Transaction,sql,SQLDialect);
197   end;
198  
# Line 175 | Line 211 | end;
211   procedure TFBStatement.TransactionEnding(aTransaction: ITransaction;
212    Force: boolean);
213   begin
214 <  if FOpen and (FExecTransactionIntf = aTransaction) then
214 >  if FOpen and ((FExecTransactionIntf as TObject) = (aTransaction as TObject)) then
215      InternalClose(Force);
216  
217    if FTransactionIntf = aTransaction then
# Line 223 | Line 259 | begin
259    Result := FSQLStatementType;
260   end;
261  
262 + function TFBStatement.GetSQLStatementTypeName: AnsiString;
263 + begin
264 +  case FSQLStatementType of
265 +  SQLUnknown: Result := 'SQL_Unknown';
266 +  SQLSelect: Result := 'SQL_Select';
267 +  SQLInsert: Result := 'SQL_Insert';
268 +  SQLUpdate: Result := 'SQL_Update';
269 +  SQLDelete: Result := 'SQL_Delete';
270 +  SQLDDL: Result := 'SQL_DDL';
271 +  SQLGetSegment: Result := 'SQL_GetSegment';
272 +  SQLPutSegment: Result := 'SQL_PutSegment';
273 +  SQLExecProcedure: Result := 'SQL_ExecProcedure';
274 +  SQLStartTransaction: Result := 'SQL_StartTransaction';
275 +  SQLCommit: Result := 'SQL_Commit';
276 +  SQLRollback: Result := 'SQL_Rollback';
277 +  SQLSelectForUpdate: Result := 'SQL_SelectForUpdate';
278 +  SQLSetGenerator: Result := 'SQL_SetGenerator';
279 +  SQLSavePoint: Result := 'SQL_SavePoint';
280 +  end;
281 + end;
282 +
283   function TFBStatement.GetSQLText: AnsiString;
284   begin
285    Result := FSQL;
286   end;
287  
288 + function TFBStatement.GetProcessedSQLText: AnsiString;
289 + begin
290 +  if FProcessedSQL = '' then
291 +    ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL);
292 +  Result := FProcessedSQL
293 + end;
294 +
295   function TFBStatement.GetSQLDialect: integer;
296   begin
297    Result := FSQLDialect;
# Line 253 | Line 317 | begin
317      Result := InternalExecute(aTransaction);
318   end;
319  
320 + procedure TFBStatement.AddToBatch;
321 + begin
322 +  IBError(ibxeBatchModeNotSupported,[]);
323 + end;
324 +
325 + function TFBStatement.ExecuteBatch(aTransaction: ITransaction
326 +  ): IBatchCompletion;
327 + begin
328 +  IBError(ibxeBatchModeNotSupported,[]);
329 + end;
330 +
331 + procedure TFBStatement.CancelBatch;
332 + begin
333 +  IBError(ibxeBatchModeNotSupported,[]);
334 + end;
335 +
336 + function TFBStatement.GetBatchCompletion: IBatchCompletion;
337 + begin
338 +  IBError(ibxeBatchModeNotSupported,[]);
339 + end;
340 +
341 + function TFBStatement.GetBatchRowLimit: integer;
342 + begin
343 +  Result := FBatchRowLimit;
344 + end;
345 +
346 + procedure TFBStatement.SetBatchRowLimit(aLimit: integer);
347 + begin
348 +  CheckChangeBatchRowLimit;
349 +  FBatchRowLimit := aLimit;
350 + end;
351 +
352 + procedure TFBStatement.SetStaleReferenceChecks(Enable: boolean);
353 + begin
354 +  FStaleReferenceChecks := Enable;
355 + end;
356 +
357 + function TFBStatement.GetStaleReferenceChecks: boolean;
358 + begin
359 +  Result := FStaleReferenceChecks;
360 + end;
361 +
362   function TFBStatement.OpenCursor(aTransaction: ITransaction): IResultSet;
363   begin
364    Close;
# Line 306 | Line 412 | end;
412  
413   function TFBStatement.GetDSQLInfo(Request: byte): ISQLInfoResults;
414   begin
415 <  Result := TSQLInfoResultsBuffer.Create;
415 >  Result := TSQLInfoResultsBuffer.Create(FFirebirdClientAPI);
416    GetDsqlInfo(Request,Result);
417   end;
418  
# Line 341 | Line 447 | begin
447    end;
448   end;
449  
450 + function TFBStatement.IsInBatchMode: boolean;
451 + begin
452 +  Result := false;
453 + end;
454 +
455 + function TFBStatement.HasBatchMode: boolean;
456 + begin
457 +  Result := false;
458 + end;
459 +
460   end.
461  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines