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} |
92 |
|
|
93 |
|
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData; |
94 |
|
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
95 |
+ |
procedure getFBVersion(version: TStrings); |
96 |
|
end; |
97 |
|
|
98 |
|
implementation |
99 |
|
|
100 |
|
uses FB25Events,FB25Transaction, FBMessages, FB25Blob, |
101 |
< |
FB25Statement, FB25Array, IBUtils; |
101 |
> |
FB25Statement, FB25Array, IBUtils, IBExternals; |
102 |
|
|
103 |
|
{ TFB25Attachment } |
104 |
|
|
108 |
|
IBError(ibxeDatabaseClosed,[nil]); |
109 |
|
end; |
110 |
|
|
111 |
< |
constructor TFB25Attachment.Create(DatabaseName: AnsiString; aDPB: IDPB; |
111 |
> |
constructor TFB25Attachment.Create(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
112 |
|
RaiseExceptionOnConnectError: boolean); |
113 |
|
begin |
114 |
+ |
FFirebird25ClientAPI := api; |
115 |
|
if aDPB = nil then |
116 |
|
begin |
117 |
|
if RaiseExceptionOnConnectError then |
118 |
|
IBError(ibxeNoDPB,[nil]); |
119 |
|
Exit; |
120 |
|
end; |
121 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnConnectError); |
121 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnConnectError); |
122 |
|
Connect; |
123 |
|
end; |
124 |
|
|
125 |
< |
constructor TFB25Attachment.CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; |
125 |
> |
constructor TFB25Attachment.CreateDatabase(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
126 |
|
RaiseExceptionOnError: boolean); |
127 |
|
var sql: AnsiString; |
128 |
|
tr_handle: TISC_TR_HANDLE; |
129 |
|
begin |
130 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnError); |
130 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError); |
131 |
> |
FFirebird25ClientAPI := api; |
132 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
133 |
|
tr_handle := nil; |
134 |
< |
with Firebird25ClientAPI do |
134 |
> |
with FFirebird25ClientAPI do |
135 |
|
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
136 |
|
SQLDialect, nil) > 0) and RaiseExceptionOnError then |
137 |
|
IBDataBaseError; |
145 |
|
GetODSAndConnectionInfo; |
146 |
|
end; |
147 |
|
|
148 |
< |
constructor TFB25Attachment.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
148 |
> |
constructor TFB25Attachment.CreateDatabase(api: TFB25ClientAPI; sql: AnsiString; aSQLDialect: integer; |
149 |
|
RaiseExceptionOnError: boolean); |
150 |
|
var tr_handle: TISC_TR_HANDLE; |
151 |
|
begin |
152 |
< |
inherited Create('',nil,RaiseExceptionOnError); |
152 |
> |
inherited Create(api,'',nil,RaiseExceptionOnError); |
153 |
> |
FFirebird25ClientAPI := api; |
154 |
|
FSQLDialect := aSQLDialect; |
155 |
|
tr_handle := nil; |
156 |
< |
with Firebird25ClientAPI do |
156 |
> |
with FFirebird25ClientAPI do |
157 |
|
begin |
158 |
|
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
159 |
|
aSQLDialect, nil) > 0) and RaiseExceptionOnError then |
168 |
|
function TFB25Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer |
169 |
|
): IDBInformation; |
170 |
|
begin |
171 |
< |
Result := TDBInformation.Create; |
172 |
< |
with Firebird25ClientAPI, Result as TDBInformation do |
171 |
> |
Result := TDBInformation.Create(FFirebird25ClientAPI); |
172 |
> |
with FFirebird25ClientAPI, Result as TDBInformation do |
173 |
|
if isc_database_info(StatusVector, @(FHandle), ReqBufLen, ReqBuffer, |
174 |
|
getBufSize, Buffer) > 0 then |
175 |
|
IBDataBaseError; |
179 |
|
begin |
180 |
|
FSQLDialect := 3; |
181 |
|
|
182 |
< |
with Firebird25ClientAPI do |
182 |
> |
with FFirebird25ClientAPI do |
183 |
|
if DPB = nil then |
184 |
|
begin |
185 |
|
if (isc_attach_database(StatusVector, Length(FDatabaseName), |
205 |
|
|
206 |
|
EndAllTransactions; |
207 |
|
{Disconnect} |
208 |
< |
with Firebird25ClientAPI do |
208 |
> |
with FFirebird25ClientAPI do |
209 |
|
if (isc_detach_database(StatusVector, @FHandle) > 0) and not Force then |
210 |
|
IBDatabaseError; |
211 |
|
FHandle := nil; |
223 |
|
begin |
224 |
|
CheckHandle; |
225 |
|
EndAllTransactions; |
226 |
< |
with Firebird25ClientAPI do |
226 |
> |
with FFirebird25ClientAPI do |
227 |
|
if isc_drop_database(StatusVector, @FHandle) > 0 then |
228 |
|
IBDatabaseError; |
229 |
|
FHandle := nil; |
233 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
234 |
|
begin |
235 |
|
CheckHandle; |
236 |
< |
Result := TFB25Transaction.Create(self,TPB,DefaultCompletion); |
236 |
> |
Result := TFB25Transaction.Create(FFirebird25ClientAPI,self,TPB,DefaultCompletion); |
237 |
|
end; |
238 |
|
|
239 |
|
function TFB25Attachment.StartTransaction(TPB: ITPB; |
240 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
241 |
|
begin |
242 |
|
CheckHandle; |
243 |
< |
Result := TFB25Transaction.Create(self,TPB,DefaultCompletion); |
243 |
> |
Result := TFB25Transaction.Create(FFirebird25ClientAPI,self,TPB,DefaultCompletion); |
244 |
|
end; |
245 |
|
|
246 |
|
function TFB25Attachment.CreateBlob(transaction: ITransaction; RelationName, |
287 |
|
begin |
288 |
|
CheckHandle; |
289 |
|
TRHandle := (Transaction as TFB25Transaction).Handle; |
290 |
< |
with Firebird25ClientAPI do |
290 |
> |
with FFirebird25ClientAPI do |
291 |
|
if isc_dsql_execute_immediate(StatusVector, @fHandle, @TRHandle, 0,PAnsiChar(sql), aSQLDialect, nil) > 0 then |
292 |
|
IBDatabaseError; |
293 |
|
SignalActivity; |
358 |
|
Result := TFB25ArrayMetaData.Create(self,Transaction as TFB25Transaction,tableName,columnName); |
359 |
|
end; |
360 |
|
|
361 |
+ |
procedure ISCVersionCallback(userArg: pointer; text: PAnsiChar); cdecl; |
362 |
+ |
begin |
363 |
+ |
TStrings(userArg).Add(text); |
364 |
+ |
end; |
365 |
+ |
|
366 |
+ |
procedure TFB25Attachment.getFBVersion(version: TStrings); |
367 |
+ |
var callback: pointer; |
368 |
+ |
begin |
369 |
+ |
callback := @ISCVersionCallback; |
370 |
+ |
version.Clear; |
371 |
+ |
with FFirebird25ClientAPI do |
372 |
+ |
if isc_version(@FHandle,TISC_CALLBACK(callback),PVoid(version)) > 0 then |
373 |
+ |
IBDataBaseError; |
374 |
+ |
end; |
375 |
+ |
|
376 |
|
end. |
377 |
|
|