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} |
64 |
|
procedure Connect; |
65 |
|
procedure Disconnect(Force: boolean=false); override; |
66 |
< |
function IsConnected: boolean; |
66 |
> |
function IsConnected: boolean; override; |
67 |
|
procedure DropDatabase; |
68 |
|
function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
69 |
|
function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
92 |
|
|
93 |
|
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData; |
94 |
|
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
92 |
– |
function GetDBInformation(Requests: array of byte): IDBInformation; overload; |
93 |
– |
function GetDBInformation(Request: byte): IDBInformation; overload; |
95 |
|
end; |
96 |
|
|
97 |
|
implementation |
98 |
|
|
99 |
|
uses FB25Events,FB25Transaction, FBMessages, FB25Blob, |
100 |
< |
FB25Statement, FB25Array; |
100 |
> |
FB25Statement, FB25Array, IBUtils; |
101 |
|
|
102 |
|
{ TFB25Attachment } |
103 |
|
|
107 |
|
IBError(ibxeDatabaseClosed,[nil]); |
108 |
|
end; |
109 |
|
|
110 |
< |
constructor TFB25Attachment.Create(DatabaseName: AnsiString; aDPB: IDPB; |
110 |
> |
constructor TFB25Attachment.Create(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
111 |
|
RaiseExceptionOnConnectError: boolean); |
112 |
|
begin |
113 |
+ |
FFirebird25ClientAPI := api; |
114 |
|
if aDPB = nil then |
115 |
|
begin |
116 |
|
if RaiseExceptionOnConnectError then |
117 |
|
IBError(ibxeNoDPB,[nil]); |
118 |
|
Exit; |
119 |
|
end; |
120 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnConnectError); |
120 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnConnectError); |
121 |
|
Connect; |
122 |
|
end; |
123 |
|
|
124 |
< |
constructor TFB25Attachment.CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; |
124 |
> |
constructor TFB25Attachment.CreateDatabase(api: TFB25ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
125 |
|
RaiseExceptionOnError: boolean); |
126 |
|
var sql: AnsiString; |
127 |
|
tr_handle: TISC_TR_HANDLE; |
128 |
|
begin |
129 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnError); |
129 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError); |
130 |
> |
FFirebird25ClientAPI := api; |
131 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
132 |
|
tr_handle := nil; |
133 |
< |
with Firebird25ClientAPI do |
133 |
> |
with FFirebird25ClientAPI do |
134 |
|
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
135 |
|
SQLDialect, nil) > 0) and RaiseExceptionOnError then |
136 |
|
IBDataBaseError; |
139 |
|
begin |
140 |
|
Disconnect; |
141 |
|
Connect; |
142 |
< |
end; |
142 |
> |
end |
143 |
> |
else |
144 |
> |
GetODSAndConnectionInfo; |
145 |
|
end; |
146 |
|
|
147 |
< |
constructor TFB25Attachment.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
147 |
> |
constructor TFB25Attachment.CreateDatabase(api: TFB25ClientAPI; sql: AnsiString; aSQLDialect: integer; |
148 |
|
RaiseExceptionOnError: boolean); |
149 |
|
var tr_handle: TISC_TR_HANDLE; |
145 |
– |
info: IDBInformation; |
146 |
– |
ConnectionType: integer; |
147 |
– |
SiteName: AnsiString; |
150 |
|
begin |
151 |
< |
inherited Create('',nil,RaiseExceptionOnError); |
151 |
> |
inherited Create(api,'',nil,RaiseExceptionOnError); |
152 |
> |
FFirebird25ClientAPI := api; |
153 |
|
FSQLDialect := aSQLDialect; |
154 |
|
tr_handle := nil; |
155 |
< |
with Firebird25ClientAPI do |
155 |
> |
with FFirebird25ClientAPI do |
156 |
|
begin |
157 |
|
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
158 |
|
aSQLDialect, nil) > 0) and RaiseExceptionOnError then |
159 |
|
IBDataBaseError; |
160 |
|
|
158 |
– |
FCharSetID := 0; |
159 |
– |
FCodePage := CP_NONE; |
160 |
– |
FHasDefaultCharSet := false; |
161 |
– |
info := GetDBInformation(isc_info_db_id); |
162 |
– |
info[0].DecodeIDCluster(ConnectionType,FDatabaseName,SiteName); |
161 |
|
end; |
162 |
+ |
GetODSAndConnectionInfo; |
163 |
+ |
ExtractConnectString(sql,FDatabaseName); |
164 |
+ |
DPBFromCreateSQL(sql); |
165 |
+ |
end; |
166 |
+ |
|
167 |
+ |
function TFB25Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer |
168 |
+ |
): IDBInformation; |
169 |
+ |
begin |
170 |
+ |
Result := TDBInformation.Create(FFirebird25ClientAPI); |
171 |
+ |
with FFirebird25ClientAPI, Result as TDBInformation do |
172 |
+ |
if isc_database_info(StatusVector, @(FHandle), ReqBufLen, ReqBuffer, |
173 |
+ |
getBufSize, Buffer) > 0 then |
174 |
+ |
IBDataBaseError; |
175 |
|
end; |
176 |
|
|
177 |
|
procedure TFB25Attachment.Connect; |
167 |
– |
var Param: IDPBItem; |
178 |
|
begin |
179 |
|
FSQLDialect := 3; |
180 |
|
|
181 |
< |
with Firebird25ClientAPI do |
181 |
> |
with FFirebird25ClientAPI do |
182 |
|
if DPB = nil then |
183 |
|
begin |
184 |
|
if (isc_attach_database(StatusVector, Length(FDatabaseName), |
193 |
|
(DPB as TDPB).getBuffer) > 0 ) and FRaiseExceptionOnConnectError then |
194 |
|
IBDatabaseError; |
195 |
|
|
186 |
– |
if IsConnected then |
187 |
– |
begin |
188 |
– |
Param := DPB.Find(isc_dpb_set_db_SQL_dialect); |
189 |
– |
if Param <> nil then |
190 |
– |
FSQLDialect := Param.AsByte; |
191 |
– |
Param := DPB.Find(isc_dpb_lc_ctype); |
192 |
– |
FHasDefaultCharSet := (Param <> nil) and |
193 |
– |
CharSetName2CharSetID(Param.AsString,FCharSetID) and |
194 |
– |
CharSetID2CodePage(FCharSetID,FCodePage) and |
195 |
– |
(FCharSetID > 1); |
196 |
– |
end; |
196 |
|
end; |
197 |
+ |
GetODSAndConnectionInfo; |
198 |
|
end; |
199 |
|
|
200 |
|
procedure TFB25Attachment.Disconnect(Force: boolean); |
204 |
|
|
205 |
|
EndAllTransactions; |
206 |
|
{Disconnect} |
207 |
< |
with Firebird25ClientAPI do |
207 |
> |
with FFirebird25ClientAPI do |
208 |
|
if (isc_detach_database(StatusVector, @FHandle) > 0) and not Force then |
209 |
|
IBDatabaseError; |
210 |
|
FHandle := nil; |
222 |
|
begin |
223 |
|
CheckHandle; |
224 |
|
EndAllTransactions; |
225 |
< |
with Firebird25ClientAPI do |
225 |
> |
with FFirebird25ClientAPI do |
226 |
|
if isc_drop_database(StatusVector, @FHandle) > 0 then |
227 |
|
IBDatabaseError; |
228 |
|
FHandle := nil; |
232 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
233 |
|
begin |
234 |
|
CheckHandle; |
235 |
< |
Result := TFB25Transaction.Create(self,TPB,DefaultCompletion); |
235 |
> |
Result := TFB25Transaction.Create(FFirebird25ClientAPI,self,TPB,DefaultCompletion); |
236 |
|
end; |
237 |
|
|
238 |
|
function TFB25Attachment.StartTransaction(TPB: ITPB; |
239 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
240 |
|
begin |
241 |
|
CheckHandle; |
242 |
< |
Result := TFB25Transaction.Create(self,TPB,DefaultCompletion); |
242 |
> |
Result := TFB25Transaction.Create(FFirebird25ClientAPI,self,TPB,DefaultCompletion); |
243 |
|
end; |
244 |
|
|
245 |
|
function TFB25Attachment.CreateBlob(transaction: ITransaction; RelationName, |
286 |
|
begin |
287 |
|
CheckHandle; |
288 |
|
TRHandle := (Transaction as TFB25Transaction).Handle; |
289 |
< |
with Firebird25ClientAPI do |
289 |
> |
with FFirebird25ClientAPI do |
290 |
|
if isc_dsql_execute_immediate(StatusVector, @fHandle, @TRHandle, 0,PAnsiChar(sql), aSQLDialect, nil) > 0 then |
291 |
|
IBDatabaseError; |
292 |
|
SignalActivity; |
340 |
|
acharSetID: cardinal; dimensions: cardinal; bounds: TArrayBounds |
341 |
|
): IArrayMetaData; |
342 |
|
begin |
343 |
< |
Result := TFB25ArrayMetaData.Create(SQLType,tableName,ColumnName,Scale,size,acharSetID,dimensions,bounds); |
343 |
> |
Result := TFB25ArrayMetaData.Create(self,SQLType,tableName,ColumnName,Scale,size,acharSetID,dimensions,bounds); |
344 |
|
end; |
345 |
|
|
346 |
|
function TFB25Attachment.GetBlobMetaData(Transaction: ITransaction; tableName, |
357 |
|
Result := TFB25ArrayMetaData.Create(self,Transaction as TFB25Transaction,tableName,columnName); |
358 |
|
end; |
359 |
|
|
360 |
– |
function TFB25Attachment.GetDBInformation(Requests: array of byte |
361 |
– |
): IDBInformation; |
362 |
– |
var ReqBuffer: PByte; |
363 |
– |
i: integer; |
364 |
– |
begin |
365 |
– |
CheckHandle; |
366 |
– |
if Length(Requests) = 1 then |
367 |
– |
Result := GetDBInformation(Requests[0]) |
368 |
– |
else |
369 |
– |
begin |
370 |
– |
Result := TDBInformation.Create; |
371 |
– |
GetMem(ReqBuffer,Length(Requests)); |
372 |
– |
try |
373 |
– |
for i := 0 to Length(Requests) - 1 do |
374 |
– |
ReqBuffer[i] := Requests[i]; |
375 |
– |
|
376 |
– |
with Firebird25ClientAPI, Result as TDBInformation do |
377 |
– |
if isc_database_info(StatusVector, @(FHandle), Length(Requests), ReqBuffer, |
378 |
– |
getBufSize, Buffer) > 0 then |
379 |
– |
IBDataBaseError; |
380 |
– |
|
381 |
– |
finally |
382 |
– |
FreeMem(ReqBuffer); |
383 |
– |
end; |
384 |
– |
end; |
385 |
– |
end; |
386 |
– |
|
387 |
– |
function TFB25Attachment.GetDBInformation(Request: byte): IDBInformation; |
388 |
– |
begin |
389 |
– |
CheckHandle; |
390 |
– |
Result := TDBInformation.Create; |
391 |
– |
with Firebird25ClientAPI, Result as TDBInformation do |
392 |
– |
if isc_database_info(StatusVector, @(FHandle), 1, @Request, |
393 |
– |
getBufSize, Buffer) > 0 then |
394 |
– |
IBDataBaseError; |
395 |
– |
end; |
396 |
– |
|
360 |
|
end. |
361 |
|
|