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; |
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; |
107 |
|
function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, |
108 |
|
DeleteCount: integer): boolean; |
109 |
|
function GetSQLStatementType: TIBSQLStatementTypes; |
110 |
+ |
function GetSQLStatementTypeName: AnsiString; |
111 |
|
function GetSQLText: AnsiString; |
112 |
|
function GetProcessedSQLText: AnsiString; |
113 |
|
function GetSQLDialect: integer; |
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; |
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 |
178 |
|
FFirebirdClientAPI := Attachment.getFirebirdAPI as TFBClientAPI; |
179 |
|
FSQLDialect := SQLDialect; |
180 |
|
FSQL := sql; |
181 |
+ |
FBatchRowLimit := DefaultBatchRowLimit; |
182 |
|
end; |
183 |
|
|
184 |
|
constructor TFBStatement.CreateWithParameterNames(Attachment: IAttachment; |
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 |
254 |
|
Result := FSQLStatementType; |
255 |
|
end; |
256 |
|
|
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; |
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; |
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 |
|
|