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 47 by tony, Mon Jan 9 15:31:51 2017 UTC vs.
Revision 345 by tony, Mon Aug 23 14:22:29 2021 UTC

# Line 28 | Line 28
28   *
29   *)
30   unit FBStatement;
31 + {$IFDEF MSWINDOWS}
32 + {$DEFINE WINDOWS}
33 + {$ENDIF}
34  
35   {$IFDEF FPC}
36 < {$mode objfpc}{$H+}
36 > {$mode delphi}
37   {$codepage UTF8}
38   {$interfaces COM}
39   {$ENDIF}
# Line 41 | 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;
# Line 57 | Line 64 | type
64      FOpen: boolean;
65      FPrepared: boolean;
66      FPrepareSeqNo: integer; {used to check for out of date references from interfaces}
67 <    FSQL: string;
68 <    FProcessedSQL: string;
67 >    FSQL: AnsiString;
68 >    FProcessedSQL: AnsiString;
69      FHasParamNames: boolean;
70      FBOF: boolean;
71      FEOF: boolean;
# Line 69 | Line 76 | type
76      FStatisticsAvailable: boolean;
77      FBeforeStats: TPerfStatistics;
78      FAfterStats: TPerfStatistics;
79 +    FCaseSensitiveParams: boolean;
80 +    FBatchRowLimit: integer;
81 +    procedure CheckChangeBatchRowLimit; virtual;
82      procedure CheckHandle; virtual; abstract;
83      procedure CheckTransaction(aTransaction: ITransaction);
84      procedure GetDsqlInfo(info_request: byte; buffer: ISQLInfoResults); overload; virtual; abstract;
85      procedure InternalPrepare;  virtual; abstract;
86 <    function InternalExecute(aTransaction: ITransaction): IResults;  virtual; abstract;
86 >    function InternalExecute(Transaction: ITransaction): IResults;  virtual; abstract;
87      function InternalOpenCursor(aTransaction: ITransaction): IResultSet;   virtual; abstract;
88 +    procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); virtual; abstract;
89      procedure FreeHandle;  virtual; abstract;
90      procedure InternalClose(Force: boolean); virtual; abstract;
91 +    function TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64;
92    public
93      constructor Create(Attachment: IAttachment; Transaction: ITransaction;
94 <      sql: string; SQLDialect: integer);
94 >      sql: AnsiString; SQLDialect: integer);
95      constructor CreateWithParameterNames(Attachment: IAttachment; Transaction: ITransaction;
96 <      sql: string;  SQLDialect: integer; GenerateParamNames: boolean =false);
96 >      sql: AnsiString;  SQLDialect: integer; GenerateParamNames: boolean =false;
97 >      CaseSensitiveParams: boolean = false);
98      destructor Destroy; override;
99      procedure Close;
100      procedure TransactionEnding(aTransaction: ITransaction; Force: boolean);
101      property SQLDialect: integer read FSQLDialect;
102 +    property FirebirdClientAPI: TFBClientAPI read FFirebirdClientAPI;
103  
104    public
105      function GetSQLParams: ISQLParams; virtual; abstract;
# Line 93 | Line 107 | type
107      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount,
108        DeleteCount: integer): boolean;
109      function GetSQLStatementType: TIBSQLStatementTypes;
110 <    function GetSQLText: string;
110 >    function GetSQLStatementTypeName: AnsiString;
111 >    function GetSQLText: AnsiString;
112 >    function GetProcessedSQLText: AnsiString;
113      function GetSQLDialect: integer;
114  
115      {GetDSQLInfo only supports isc_info_sql_stmt_type, isc_info_sql_get_plan, isc_info_sql_records}
116      procedure Prepare(aTransaction: ITransaction=nil); virtual;
117      function Execute(aTransaction: ITransaction=nil): IResults;
118      function OpenCursor(aTransaction: ITransaction=nil): IResultSet;
119 <    function CreateBlob(paramName: string): IBlob; overload;
119 >    function CreateBlob(paramName: AnsiString): IBlob; overload;
120      function CreateBlob(index: integer): IBlob; overload;
121      function CreateBlob(column: TColumnMetaData): IBlob; overload; virtual; abstract;
122 <    function CreateArray(paramName: string): IArray; overload;
122 >    function CreateArray(paramName: AnsiString): IArray; overload;
123      function CreateArray(index: integer): IArray;  overload;
124      function CreateArray(column: TColumnMetaData): IArray; overload; virtual; abstract;
125      function GetAttachment: IAttachment;
# Line 112 | Line 128 | type
128      procedure SetRetainInterfaces(aValue: boolean); virtual;
129      procedure EnableStatistics(aValue: boolean);
130      function GetPerfStatistics(var stats: TPerfCounters): boolean;
131 +    function IsInBatchMode: boolean; virtual;
132 +    function HasBatchMode: boolean; virtual;
133 +  public
134 +    {IBatch support}
135 +    procedure AddToBatch; virtual;
136 +    function ExecuteBatch(aTransaction: ITransaction): IBatchCompletion; virtual;
137 +    procedure CancelBatch; virtual;
138 +    function GetBatchCompletion: IBatchCompletion; virtual;
139 +    function GetBatchRowLimit: integer;
140 +    procedure SetBatchRowLimit(aLimit: integer);
141 +  public
142      property ChangeSeqNo: integer read FChangeSeqNo;
143      property SQLParams: ISQLParams read GetSQLParams;
144      property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
# Line 123 | Line 150 | uses FBMessages;
150  
151   { TFBStatement }
152  
153 + procedure TFBStatement.CheckChangeBatchRowLimit;
154 + begin
155 +  //Do Nothing
156 + end;
157 +
158   procedure TFBStatement.CheckTransaction(aTransaction: ITransaction);
159   begin
160    if (aTransaction = nil) then
# Line 132 | Line 164 | begin
164      IBError(ibxeNotInTransaction,[]);
165   end;
166  
167 + function TFBStatement.TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64;
168 + begin
169 +  Result := TimeStamp.Time + Int64(timestamp.date)*msecsperday;
170 + end;
171 +
172   constructor TFBStatement.Create(Attachment: IAttachment;
173 <  Transaction: ITransaction; sql: string; SQLDialect: integer);
173 >  Transaction: ITransaction; sql: AnsiString; SQLDialect: integer);
174   begin
175    inherited Create(Transaction as TFBTransaction,2);
176    FAttachmentIntf := Attachment;
177    FTransactionIntf := Transaction;
178 +  FFirebirdClientAPI := Attachment.getFirebirdAPI as TFBClientAPI;
179    FSQLDialect := SQLDialect;
180    FSQL := sql;
181 +  FBatchRowLimit := DefaultBatchRowLimit;
182   end;
183  
184   constructor TFBStatement.CreateWithParameterNames(Attachment: IAttachment;
185 <  Transaction: ITransaction; sql: string; SQLDialect: integer;
186 <  GenerateParamNames: boolean);
185 >  Transaction: ITransaction; sql: AnsiString; SQLDialect: integer;
186 >  GenerateParamNames: boolean; CaseSensitiveParams: boolean);
187   begin
188    FHasParamNames := true;
189    FGenerateParamNames := GenerateParamNames;
190 +  FCaseSensitiveParams := CaseSensitiveParams;
191    Create(Attachment,Transaction,sql,SQLDialect);
192   end;
193  
# Line 166 | Line 206 | end;
206   procedure TFBStatement.TransactionEnding(aTransaction: ITransaction;
207    Force: boolean);
208   begin
209 <  if FOpen and (FExecTransactionIntf = aTransaction) then
209 >  if FOpen and ((FExecTransactionIntf as TObject) = (aTransaction as TObject)) then
210      InternalClose(Force);
211  
212    if FTransactionIntf = aTransaction then
# Line 214 | Line 254 | begin
254    Result := FSQLStatementType;
255   end;
256  
257 < function TFBStatement.GetSQLText: string;
257 > function TFBStatement.GetSQLStatementTypeName: AnsiString;
258 > begin
259 >  case FSQLStatementType of
260 >  SQLUnknown: Result := 'SQL_Unknown';
261 >  SQLSelect: Result := 'SQL_Select';
262 >  SQLInsert: Result := 'SQL_Insert';
263 >  SQLUpdate: Result := 'SQL_Update';
264 >  SQLDelete: Result := 'SQL_Delete';
265 >  SQLDDL: Result := 'SQL_DDL';
266 >  SQLGetSegment: Result := 'SQL_GetSegment';
267 >  SQLPutSegment: Result := 'SQL_PutSegment';
268 >  SQLExecProcedure: Result := 'SQL_ExecProcedure';
269 >  SQLStartTransaction: Result := 'SQL_StartTransaction';
270 >  SQLCommit: Result := 'SQL_Commit';
271 >  SQLRollback: Result := 'SQL_Rollback';
272 >  SQLSelectForUpdate: Result := 'SQL_SelectForUpdate';
273 >  SQLSetGenerator: Result := 'SQL_SetGenerator';
274 >  SQLSavePoint: Result := 'SQL_SavePoint';
275 >  end;
276 > end;
277 >
278 > function TFBStatement.GetSQLText: AnsiString;
279   begin
280    Result := FSQL;
281   end;
282  
283 + function TFBStatement.GetProcessedSQLText: AnsiString;
284 + begin
285 +  if FProcessedSQL = '' then
286 +    ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL);
287 +  Result := FProcessedSQL
288 + end;
289 +
290   function TFBStatement.GetSQLDialect: integer;
291   begin
292    Result := FSQLDialect;
# Line 244 | Line 312 | begin
312      Result := InternalExecute(aTransaction);
313   end;
314  
315 + procedure TFBStatement.AddToBatch;
316 + begin
317 +  IBError(ibxeBatchModeNotSupported,[]);
318 + end;
319 +
320 + function TFBStatement.ExecuteBatch(aTransaction: ITransaction
321 +  ): IBatchCompletion;
322 + begin
323 +  IBError(ibxeBatchModeNotSupported,[]);
324 + end;
325 +
326 + procedure TFBStatement.CancelBatch;
327 + begin
328 +  IBError(ibxeBatchModeNotSupported,[]);
329 + end;
330 +
331 + function TFBStatement.GetBatchCompletion: IBatchCompletion;
332 + begin
333 +  IBError(ibxeBatchModeNotSupported,[]);
334 + end;
335 +
336 + function TFBStatement.GetBatchRowLimit: integer;
337 + begin
338 +  Result := FBatchRowLimit;
339 + end;
340 +
341 + procedure TFBStatement.SetBatchRowLimit(aLimit: integer);
342 + begin
343 +  CheckChangeBatchRowLimit;
344 +  FBatchRowLimit := aLimit;
345 + end;
346 +
347   function TFBStatement.OpenCursor(aTransaction: ITransaction): IResultSet;
348   begin
349    Close;
# Line 253 | Line 353 | begin
353      Result := InternalOpenCursor(aTransaction);
354   end;
355  
356 < function TFBStatement.CreateBlob(paramName: string): IBlob;
356 > function TFBStatement.CreateBlob(paramName: AnsiString): IBlob;
357   var column: TColumnMetaData;
358   begin
359    InternalPrepare;
# Line 269 | Line 369 | begin
369    Result := CreateBlob(SQLParams[index] as TSQLParam);
370   end;
371  
372 < function TFBStatement.CreateArray(paramName: string): IArray;
372 > function TFBStatement.CreateArray(paramName: AnsiString): IArray;
373   var column: TColumnMetaData;
374   begin
375    InternalPrepare;
# Line 297 | Line 397 | end;
397  
398   function TFBStatement.GetDSQLInfo(Request: byte): ISQLInfoResults;
399   begin
400 <  Result := TSQLInfoResultsBuffer.Create;
400 >  Result := TSQLInfoResultsBuffer.Create(FFirebirdClientAPI);
401    GetDsqlInfo(Request,Result);
402   end;
403  
# Line 332 | Line 432 | begin
432    end;
433   end;
434  
435 + function TFBStatement.IsInBatchMode: boolean;
436 + begin
437 +  Result := false;
438 + end;
439 +
440 + function TFBStatement.HasBatchMode: boolean;
441 + begin
442 +  Result := false;
443 + end;
444 +
445   end.
446  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines