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; |
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; |
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); |
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; |
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; |
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 |
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 |
|
|
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 |
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; |
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; |
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 |
|
|