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} |
52 |
|
TFBStatement = class(TActivityReporter) |
53 |
|
private |
54 |
|
FAttachmentIntf: IAttachment; |
55 |
+ |
FFirebirdClientAPI: TFBClientAPI; |
56 |
|
protected |
57 |
|
FTransactionIntf: ITransaction; |
58 |
|
FExecTransactionIntf: ITransaction; |
61 |
|
FOpen: boolean; |
62 |
|
FPrepared: boolean; |
63 |
|
FPrepareSeqNo: integer; {used to check for out of date references from interfaces} |
64 |
< |
FSQL: string; |
65 |
< |
FProcessedSQL: string; |
64 |
> |
FSQL: AnsiString; |
65 |
> |
FProcessedSQL: AnsiString; |
66 |
|
FHasParamNames: boolean; |
67 |
|
FBOF: boolean; |
68 |
|
FEOF: boolean; |
79 |
|
procedure InternalPrepare; virtual; abstract; |
80 |
|
function InternalExecute(aTransaction: ITransaction): IResults; virtual; abstract; |
81 |
|
function InternalOpenCursor(aTransaction: ITransaction): IResultSet; virtual; abstract; |
82 |
+ |
procedure ProcessSQL(sql: AnsiString; GenerateParamNames: boolean; var processedSQL: AnsiString); virtual; abstract; |
83 |
|
procedure FreeHandle; virtual; abstract; |
84 |
|
procedure InternalClose(Force: boolean); virtual; abstract; |
85 |
+ |
function TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64; |
86 |
|
public |
87 |
|
constructor Create(Attachment: IAttachment; Transaction: ITransaction; |
88 |
< |
sql: string; SQLDialect: integer); |
88 |
> |
sql: AnsiString; SQLDialect: integer); |
89 |
|
constructor CreateWithParameterNames(Attachment: IAttachment; Transaction: ITransaction; |
90 |
< |
sql: string; SQLDialect: integer; GenerateParamNames: boolean =false); |
90 |
> |
sql: AnsiString; SQLDialect: integer; GenerateParamNames: boolean =false); |
91 |
|
destructor Destroy; override; |
92 |
|
procedure Close; |
93 |
|
procedure TransactionEnding(aTransaction: ITransaction; Force: boolean); |
94 |
|
property SQLDialect: integer read FSQLDialect; |
95 |
+ |
property FirebirdClientAPI: TFBClientAPI read FFirebirdClientAPI; |
96 |
|
|
97 |
|
public |
98 |
|
function GetSQLParams: ISQLParams; virtual; abstract; |
100 |
|
function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, |
101 |
|
DeleteCount: integer): boolean; |
102 |
|
function GetSQLStatementType: TIBSQLStatementTypes; |
103 |
< |
function GetSQLText: string; |
103 |
> |
function GetSQLText: AnsiString; |
104 |
> |
function GetProcessedSQLText: AnsiString; |
105 |
|
function GetSQLDialect: integer; |
106 |
|
|
107 |
|
{GetDSQLInfo only supports isc_info_sql_stmt_type, isc_info_sql_get_plan, isc_info_sql_records} |
108 |
|
procedure Prepare(aTransaction: ITransaction=nil); virtual; |
109 |
|
function Execute(aTransaction: ITransaction=nil): IResults; |
110 |
|
function OpenCursor(aTransaction: ITransaction=nil): IResultSet; |
111 |
< |
function CreateBlob(paramName: string): IBlob; overload; |
111 |
> |
function CreateBlob(paramName: AnsiString): IBlob; overload; |
112 |
|
function CreateBlob(index: integer): IBlob; overload; |
113 |
|
function CreateBlob(column: TColumnMetaData): IBlob; overload; virtual; abstract; |
114 |
< |
function CreateArray(paramName: string): IArray; overload; |
114 |
> |
function CreateArray(paramName: AnsiString): IArray; overload; |
115 |
|
function CreateArray(index: integer): IArray; overload; |
116 |
|
function CreateArray(column: TColumnMetaData): IArray; overload; virtual; abstract; |
117 |
|
function GetAttachment: IAttachment; |
140 |
|
IBError(ibxeNotInTransaction,[]); |
141 |
|
end; |
142 |
|
|
143 |
+ |
function TFBStatement.TimeStampToMSecs(const TimeStamp: TTimeStamp): Int64; |
144 |
+ |
begin |
145 |
+ |
Result := TimeStamp.Time + Int64(timestamp.date)*msecsperday; |
146 |
+ |
end; |
147 |
+ |
|
148 |
|
constructor TFBStatement.Create(Attachment: IAttachment; |
149 |
< |
Transaction: ITransaction; sql: string; SQLDialect: integer); |
149 |
> |
Transaction: ITransaction; sql: AnsiString; SQLDialect: integer); |
150 |
|
begin |
151 |
|
inherited Create(Transaction as TFBTransaction,2); |
152 |
|
FAttachmentIntf := Attachment; |
153 |
|
FTransactionIntf := Transaction; |
154 |
+ |
FFirebirdClientAPI := Attachment.getFirebirdAPI as TFBClientAPI; |
155 |
|
FSQLDialect := SQLDialect; |
156 |
|
FSQL := sql; |
157 |
|
end; |
158 |
|
|
159 |
|
constructor TFBStatement.CreateWithParameterNames(Attachment: IAttachment; |
160 |
< |
Transaction: ITransaction; sql: string; SQLDialect: integer; |
160 |
> |
Transaction: ITransaction; sql: AnsiString; SQLDialect: integer; |
161 |
|
GenerateParamNames: boolean); |
162 |
|
begin |
163 |
|
FHasParamNames := true; |
228 |
|
Result := FSQLStatementType; |
229 |
|
end; |
230 |
|
|
231 |
< |
function TFBStatement.GetSQLText: string; |
231 |
> |
function TFBStatement.GetSQLText: AnsiString; |
232 |
|
begin |
233 |
|
Result := FSQL; |
234 |
|
end; |
235 |
|
|
236 |
+ |
function TFBStatement.GetProcessedSQLText: AnsiString; |
237 |
+ |
begin |
238 |
+ |
if FProcessedSQL = '' then |
239 |
+ |
ProcessSQL(FSQL,FGenerateParamNames,FProcessedSQL); |
240 |
+ |
Result := FProcessedSQL |
241 |
+ |
end; |
242 |
+ |
|
243 |
|
function TFBStatement.GetSQLDialect: integer; |
244 |
|
begin |
245 |
|
Result := FSQLDialect; |
274 |
|
Result := InternalOpenCursor(aTransaction); |
275 |
|
end; |
276 |
|
|
277 |
< |
function TFBStatement.CreateBlob(paramName: string): IBlob; |
277 |
> |
function TFBStatement.CreateBlob(paramName: AnsiString): IBlob; |
278 |
|
var column: TColumnMetaData; |
279 |
|
begin |
280 |
|
InternalPrepare; |
290 |
|
Result := CreateBlob(SQLParams[index] as TSQLParam); |
291 |
|
end; |
292 |
|
|
293 |
< |
function TFBStatement.CreateArray(paramName: string): IArray; |
293 |
> |
function TFBStatement.CreateArray(paramName: AnsiString): IArray; |
294 |
|
var column: TColumnMetaData; |
295 |
|
begin |
296 |
|
InternalPrepare; |
318 |
|
|
319 |
|
function TFBStatement.GetDSQLInfo(Request: byte): ISQLInfoResults; |
320 |
|
begin |
321 |
< |
Result := TSQLInfoResultsBuffer.Create; |
321 |
> |
Result := TSQLInfoResultsBuffer.Create(FFirebirdClientAPI); |
322 |
|
GetDsqlInfo(Request,Result); |
323 |
|
end; |
324 |
|
|