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; |
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; |
93 |
|
constructor Create(Attachment: IAttachment; Transaction: ITransaction; |
94 |
|
sql: AnsiString; SQLDialect: integer); |
95 |
|
constructor CreateWithParameterNames(Attachment: IAttachment; Transaction: ITransaction; |
96 |
< |
sql: AnsiString; 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; |
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; |
114 |
|
|
115 |
|
{GetDSQLInfo only supports isc_info_sql_stmt_type, isc_info_sql_get_plan, isc_info_sql_records} |
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 |
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: AnsiString; SQLDialect: integer; |
186 |
< |
GenerateParamNames: boolean); |
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 |
|
|
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; |
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; |
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; |
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 |
|
|
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 |
|
|