46 |
|
TFB25Attachment = class(TFBAttachment, IAttachment, IActivityMonitor) |
47 |
|
private |
48 |
|
FHandle: TISC_DB_HANDLE; |
49 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
50 |
|
protected |
51 |
|
procedure CheckHandle; override; |
52 |
|
public |
53 |
< |
constructor Create(DatabaseName: AnsiString; aDPB: IDPB; |
53 |
> |
constructor Create(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
54 |
|
RaiseExceptionOnConnectError: boolean); |
55 |
< |
constructor CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean); overload; |
56 |
< |
constructor CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
55 |
> |
constructor CreateDatabase(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean); overload; |
56 |
> |
constructor CreateDatabase(api: TFB25ClientAPI; sql: AnsiString; aSQLDialect: integer; |
57 |
|
RaiseExceptionOnError: boolean); overload; |
58 |
+ |
function GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; override; |
59 |
|
property Handle: TISC_DB_HANDLE read FHandle; |
60 |
+ |
property Firebird25ClientAPI: TFB25ClientAPI read FFirebird25ClientAPI; |
61 |
|
|
62 |
|
public |
63 |
|
{IAttachment} |
70 |
|
procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); override; |
71 |
|
function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; override; |
72 |
|
function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString; |
73 |
< |
aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; override; |
73 |
> |
aSQLDialect: integer; GenerateParamNames: boolean=false; |
74 |
> |
CaseSensitiveParams: boolean=false): IStatement; override; |
75 |
|
function GetEventHandler(Events: TStrings): IEvents; override; |
76 |
|
function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload; |
77 |
|
function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload; |
93 |
|
|
94 |
|
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData; |
95 |
|
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
96 |
< |
function GetDBInformation(Requests: array of byte): IDBInformation; overload; override; |
93 |
< |
function GetDBInformation(Request: byte): IDBInformation; overload; override; |
96 |
> |
procedure getFBVersion(version: TStrings); |
97 |
|
end; |
98 |
|
|
99 |
|
implementation |
100 |
|
|
101 |
|
uses FB25Events,FB25Transaction, FBMessages, FB25Blob, |
102 |
< |
FB25Statement, FB25Array, IBUtils; |
102 |
> |
FB25Statement, FB25Array, IBUtils, IBExternals; |
103 |
|
|
104 |
|
{ TFB25Attachment } |
105 |
|
|
109 |
|
IBError(ibxeDatabaseClosed,[nil]); |
110 |
|
end; |
111 |
|
|
112 |
< |
constructor TFB25Attachment.Create(DatabaseName: AnsiString; aDPB: IDPB; |
112 |
> |
constructor TFB25Attachment.Create(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
113 |
|
RaiseExceptionOnConnectError: boolean); |
114 |
|
begin |
115 |
+ |
FFirebird25ClientAPI := api; |
116 |
|
if aDPB = nil then |
117 |
|
begin |
118 |
|
if RaiseExceptionOnConnectError then |
119 |
|
IBError(ibxeNoDPB,[nil]); |
120 |
|
Exit; |
121 |
|
end; |
122 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnConnectError); |
122 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnConnectError); |
123 |
|
Connect; |
124 |
|
end; |
125 |
|
|
126 |
< |
constructor TFB25Attachment.CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; |
126 |
> |
constructor TFB25Attachment.CreateDatabase(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
127 |
|
RaiseExceptionOnError: boolean); |
128 |
|
var sql: AnsiString; |
129 |
|
tr_handle: TISC_TR_HANDLE; |
130 |
|
begin |
131 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnError); |
131 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError); |
132 |
> |
FFirebird25ClientAPI := api; |
133 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
134 |
|
tr_handle := nil; |
135 |
< |
with Firebird25ClientAPI do |
135 |
> |
with FFirebird25ClientAPI do |
136 |
|
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
137 |
|
SQLDialect, nil) > 0) and RaiseExceptionOnError then |
138 |
|
IBDataBaseError; |
146 |
|
GetODSAndConnectionInfo; |
147 |
|
end; |
148 |
|
|
149 |
< |
constructor TFB25Attachment.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
149 |
> |
constructor TFB25Attachment.CreateDatabase(api: TFB25ClientAPI; sql: AnsiString; aSQLDialect: integer; |
150 |
|
RaiseExceptionOnError: boolean); |
151 |
|
var tr_handle: TISC_TR_HANDLE; |
152 |
|
begin |
153 |
< |
inherited Create('',nil,RaiseExceptionOnError); |
153 |
> |
inherited Create(api,'',nil,RaiseExceptionOnError); |
154 |
> |
FFirebird25ClientAPI := api; |
155 |
|
FSQLDialect := aSQLDialect; |
156 |
|
tr_handle := nil; |
157 |
< |
with Firebird25ClientAPI do |
157 |
> |
with FFirebird25ClientAPI do |
158 |
|
begin |
159 |
|
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
160 |
|
aSQLDialect, nil) > 0) and RaiseExceptionOnError then |
166 |
|
DPBFromCreateSQL(sql); |
167 |
|
end; |
168 |
|
|
169 |
+ |
function TFB25Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer |
170 |
+ |
): IDBInformation; |
171 |
+ |
begin |
172 |
+ |
Result := TDBInformation.Create(FFirebird25ClientAPI); |
173 |
+ |
with FFirebird25ClientAPI, Result as TDBInformation do |
174 |
+ |
if isc_database_info(StatusVector, @(FHandle), ReqBufLen, ReqBuffer, |
175 |
+ |
getBufSize, Buffer) > 0 then |
176 |
+ |
IBDataBaseError; |
177 |
+ |
end; |
178 |
+ |
|
179 |
|
procedure TFB25Attachment.Connect; |
180 |
|
begin |
181 |
|
FSQLDialect := 3; |
182 |
|
|
183 |
< |
with Firebird25ClientAPI do |
183 |
> |
with FFirebird25ClientAPI do |
184 |
|
if DPB = nil then |
185 |
|
begin |
186 |
|
if (isc_attach_database(StatusVector, Length(FDatabaseName), |
206 |
|
|
207 |
|
EndAllTransactions; |
208 |
|
{Disconnect} |
209 |
< |
with Firebird25ClientAPI do |
209 |
> |
with FFirebird25ClientAPI do |
210 |
|
if (isc_detach_database(StatusVector, @FHandle) > 0) and not Force then |
211 |
|
IBDatabaseError; |
212 |
|
FHandle := nil; |
224 |
|
begin |
225 |
|
CheckHandle; |
226 |
|
EndAllTransactions; |
227 |
< |
with Firebird25ClientAPI do |
227 |
> |
with FFirebird25ClientAPI do |
228 |
|
if isc_drop_database(StatusVector, @FHandle) > 0 then |
229 |
|
IBDatabaseError; |
230 |
|
FHandle := nil; |
234 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
235 |
|
begin |
236 |
|
CheckHandle; |
237 |
< |
Result := TFB25Transaction.Create(self,TPB,DefaultCompletion); |
237 |
> |
Result := TFB25Transaction.Create(FFirebird25ClientAPI,self,TPB,DefaultCompletion); |
238 |
|
end; |
239 |
|
|
240 |
|
function TFB25Attachment.StartTransaction(TPB: ITPB; |
241 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
242 |
|
begin |
243 |
|
CheckHandle; |
244 |
< |
Result := TFB25Transaction.Create(self,TPB,DefaultCompletion); |
244 |
> |
Result := TFB25Transaction.Create(FFirebird25ClientAPI,self,TPB,DefaultCompletion); |
245 |
|
end; |
246 |
|
|
247 |
|
function TFB25Attachment.CreateBlob(transaction: ITransaction; RelationName, |
288 |
|
begin |
289 |
|
CheckHandle; |
290 |
|
TRHandle := (Transaction as TFB25Transaction).Handle; |
291 |
< |
with Firebird25ClientAPI do |
291 |
> |
with FFirebird25ClientAPI do |
292 |
|
if isc_dsql_execute_immediate(StatusVector, @fHandle, @TRHandle, 0,PAnsiChar(sql), aSQLDialect, nil) > 0 then |
293 |
|
IBDatabaseError; |
294 |
|
SignalActivity; |
302 |
|
end; |
303 |
|
|
304 |
|
function TFB25Attachment.PrepareWithNamedParameters(transaction: ITransaction; |
305 |
< |
sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean): IStatement; |
305 |
> |
sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean; |
306 |
> |
CaseSensitiveParams: boolean): IStatement; |
307 |
|
begin |
308 |
|
CheckHandle; |
309 |
|
Result := TFB25Statement.CreateWithParameterNames(self,transaction,sql,aSQLDialect, |
310 |
< |
GenerateParamNames); |
310 |
> |
GenerateParamNames,CaseSensitiveParams); |
311 |
|
end; |
312 |
|
|
313 |
|
function TFB25Attachment.GetEventHandler(Events: TStrings): IEvents; |
360 |
|
Result := TFB25ArrayMetaData.Create(self,Transaction as TFB25Transaction,tableName,columnName); |
361 |
|
end; |
362 |
|
|
363 |
< |
function TFB25Attachment.GetDBInformation(Requests: array of byte |
347 |
< |
): IDBInformation; |
348 |
< |
var ReqBuffer: PByte; |
349 |
< |
i: integer; |
363 |
> |
procedure ISCVersionCallback(userArg: pointer; text: PAnsiChar); cdecl; |
364 |
|
begin |
365 |
< |
CheckHandle; |
352 |
< |
if Length(Requests) = 1 then |
353 |
< |
Result := GetDBInformation(Requests[0]) |
354 |
< |
else |
355 |
< |
begin |
356 |
< |
Result := TDBInformation.Create; |
357 |
< |
GetMem(ReqBuffer,Length(Requests)); |
358 |
< |
try |
359 |
< |
for i := 0 to Length(Requests) - 1 do |
360 |
< |
ReqBuffer[i] := Requests[i]; |
361 |
< |
|
362 |
< |
with Firebird25ClientAPI, Result as TDBInformation do |
363 |
< |
if isc_database_info(StatusVector, @(FHandle), Length(Requests), ReqBuffer, |
364 |
< |
getBufSize, Buffer) > 0 then |
365 |
< |
IBDataBaseError; |
366 |
< |
|
367 |
< |
finally |
368 |
< |
FreeMem(ReqBuffer); |
369 |
< |
end; |
370 |
< |
end; |
365 |
> |
TStrings(userArg).Add(text); |
366 |
|
end; |
367 |
|
|
368 |
< |
function TFB25Attachment.GetDBInformation(Request: byte): IDBInformation; |
368 |
> |
procedure TFB25Attachment.getFBVersion(version: TStrings); |
369 |
> |
var callback: pointer; |
370 |
|
begin |
371 |
< |
CheckHandle; |
372 |
< |
Result := TDBInformation.Create; |
373 |
< |
with Firebird25ClientAPI, Result as TDBInformation do |
374 |
< |
if isc_database_info(StatusVector, @(FHandle), 1, @Request, |
375 |
< |
getBufSize, Buffer) > 0 then |
380 |
< |
IBDataBaseError; |
371 |
> |
callback := @ISCVersionCallback; |
372 |
> |
version.Clear; |
373 |
> |
with FFirebird25ClientAPI do |
374 |
> |
if isc_version(@FHandle,TISC_CALLBACK(callback),PVoid(version)) > 0 then |
375 |
> |
IBDataBaseError; |
376 |
|
end; |
377 |
|
|
378 |
|
end. |