46 |
|
TFB30Attachment = class(TFBAttachment,IAttachment, IActivityMonitor) |
47 |
|
private |
48 |
|
FAttachmentIntf: Firebird.IAttachment; |
49 |
+ |
FFirebird30ClientAPI: TFB30ClientAPI; |
50 |
|
protected |
51 |
|
procedure CheckHandle; override; |
52 |
|
public |
53 |
< |
constructor Create(DatabaseName: AnsiString; aDPB: IDPB; |
53 |
> |
constructor Create(api: TFB30ClientAPI; 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: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean); overload; |
56 |
> |
constructor CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer; |
57 |
|
RaiseExceptionOnError: boolean); overload; |
58 |
|
destructor Destroy; override; |
59 |
+ |
function GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; |
60 |
+ |
override; |
61 |
|
property AttachmentIntf: Firebird.IAttachment read FAttachmentIntf; |
62 |
+ |
property Firebird30ClientAPI: TFB30ClientAPI read FFirebird30ClientAPI; |
63 |
|
|
64 |
|
public |
65 |
|
{IAttachment} |
66 |
|
procedure Connect; |
67 |
|
procedure Disconnect(Force: boolean=false); override; |
68 |
< |
function IsConnected: boolean; |
68 |
> |
function IsConnected: boolean; override; |
69 |
|
procedure DropDatabase; |
70 |
|
function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
71 |
|
function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
91 |
|
function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload; |
92 |
|
function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; |
93 |
|
columnName: AnsiString; Scale: integer; size: cardinal; aCharSetID: cardinal; |
94 |
< |
dimensions: cardinal; bounds: TArrayBounds): IArrayMetaData; |
94 |
> |
dimensions: cardinal; bounds: TArrayBounds): IArrayMetaData; |
95 |
|
|
96 |
|
|
97 |
|
{Database Information} |
98 |
|
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData; |
99 |
|
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
96 |
– |
function GetDBInformation(Requests: array of byte): IDBInformation; overload; |
97 |
– |
function GetDBInformation(Request: byte): IDBInformation; overload; |
100 |
|
end; |
101 |
|
|
102 |
|
implementation |
103 |
|
|
104 |
|
uses FB30Transaction, FB30Statement, FB30Array, FB30Blob, FBMessages, |
105 |
< |
FBOutputBlock, FB30Events; |
105 |
> |
FBOutputBlock, FB30Events, IBUtils; |
106 |
|
|
107 |
|
{ TFB30Attachment } |
108 |
|
|
112 |
|
IBError(ibxeDatabaseClosed,[nil]); |
113 |
|
end; |
114 |
|
|
115 |
< |
constructor TFB30Attachment.Create(DatabaseName: AnsiString; aDPB: IDPB; |
115 |
> |
constructor TFB30Attachment.Create(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
116 |
|
RaiseExceptionOnConnectError: boolean); |
117 |
|
begin |
118 |
+ |
FFirebird30ClientAPI := api; |
119 |
|
if aDPB = nil then |
120 |
|
begin |
121 |
|
if RaiseExceptionOnConnectError then |
122 |
|
IBError(ibxeNoDPB,[nil]); |
123 |
|
Exit; |
124 |
|
end; |
125 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnConnectError); |
125 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnConnectError); |
126 |
|
Connect; |
127 |
|
end; |
128 |
|
|
129 |
< |
constructor TFB30Attachment.CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; |
129 |
> |
constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
130 |
|
RaiseExceptionOnError: boolean); |
131 |
|
var Param: IDPBItem; |
132 |
|
sql: AnsiString; |
133 |
|
IsCreateDB: boolean; |
134 |
|
begin |
135 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnError); |
135 |
> |
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError); |
136 |
> |
FFirebird30ClientAPI := api; |
137 |
|
IsCreateDB := true; |
138 |
|
if aDPB <> nil then |
139 |
|
begin |
142 |
|
FSQLDialect := Param.AsByte; |
143 |
|
end; |
144 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
145 |
< |
with Firebird30ClientAPI do |
145 |
> |
with FFirebird30ClientAPI do |
146 |
|
begin |
147 |
|
FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
148 |
|
PAnsiChar(sql),FSQLDialect,@IsCreateDB); |
155 |
|
begin |
156 |
|
Disconnect; |
157 |
|
Connect; |
158 |
< |
end; |
158 |
> |
end |
159 |
> |
else |
160 |
> |
GetODSAndConnectionInfo; |
161 |
|
end; |
162 |
|
end; |
163 |
|
|
164 |
< |
constructor TFB30Attachment.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
164 |
> |
constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer; |
165 |
|
RaiseExceptionOnError: boolean); |
166 |
|
var IsCreateDB: boolean; |
161 |
– |
info: IDBInformation; |
162 |
– |
ConnectionType: integer; |
163 |
– |
SiteName: AnsiString; |
167 |
|
begin |
168 |
< |
inherited Create('',nil,RaiseExceptionOnError); |
168 |
> |
inherited Create(api,'',nil,RaiseExceptionOnError); |
169 |
> |
FFirebird30ClientAPI := api; |
170 |
|
FSQLDialect := aSQLDialect; |
171 |
< |
with Firebird30ClientAPI do |
171 |
> |
with FFirebird30ClientAPI do |
172 |
|
begin |
173 |
|
FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
174 |
|
PAnsiChar(sql),aSQLDialect,@IsCreateDB); |
175 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
176 |
|
if InErrorState then |
177 |
|
FAttachmentIntf := nil; |
174 |
– |
FCharSetID := 0; |
175 |
– |
FCodePage := CP_NONE; |
176 |
– |
FHasDefaultCharSet := false; |
177 |
– |
info := GetDBInformation(isc_info_db_id); |
178 |
– |
info[0].DecodeIDCluster(ConnectionType,FDatabaseName,SiteName); |
178 |
|
end; |
179 |
+ |
GetODSAndConnectionInfo; |
180 |
+ |
ExtractConnectString(sql,FDatabaseName); |
181 |
+ |
DPBFromCreateSQL(sql); |
182 |
|
end; |
183 |
|
|
184 |
|
destructor TFB30Attachment.Destroy; |
188 |
|
FAttachmentIntf.release; |
189 |
|
end; |
190 |
|
|
191 |
+ |
function TFB30Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; |
192 |
+ |
begin |
193 |
+ |
Result := TDBInformation.Create(Firebird30ClientAPI); |
194 |
+ |
with FFirebird30ClientAPI, Result as TDBInformation do |
195 |
+ |
begin |
196 |
+ |
FAttachmentIntf.getInfo(StatusIntf, ReqBufLen, BytePtr(ReqBuffer), |
197 |
+ |
getBufSize, BytePtr(Buffer)); |
198 |
+ |
Check4DataBaseError; |
199 |
+ |
end |
200 |
+ |
end; |
201 |
+ |
|
202 |
|
procedure TFB30Attachment.Connect; |
190 |
– |
var Param: IDPBItem; |
203 |
|
begin |
204 |
< |
with Firebird30ClientAPI do |
204 |
> |
with FFirebird30ClientAPI do |
205 |
|
begin |
206 |
|
FAttachmentIntf := ProviderIntf.attachDatabase(StatusIntf,PAnsiChar(FDatabaseName), |
207 |
|
(DPB as TDPB).getDataLength, |
210 |
|
if InErrorState then |
211 |
|
FAttachmentIntf := nil |
212 |
|
else |
213 |
< |
begin |
202 |
< |
Param := DPB.Find(isc_dpb_set_db_SQL_dialect); |
203 |
< |
if Param <> nil then |
204 |
< |
FSQLDialect := Param.AsByte; |
205 |
< |
Param := DPB.Find(isc_dpb_lc_ctype); |
206 |
< |
FHasDefaultCharSet := (Param <> nil) and |
207 |
< |
CharSetName2CharSetID(Param.AsString,FCharSetID) and |
208 |
< |
CharSetID2CodePage(FCharSetID,FCodePage) and |
209 |
< |
(FCharSetID > 1); |
210 |
< |
end; |
213 |
> |
GetODSAndConnectionInfo; |
214 |
|
end; |
215 |
|
end; |
216 |
|
|
217 |
|
procedure TFB30Attachment.Disconnect(Force: boolean); |
218 |
|
begin |
219 |
|
if IsConnected then |
220 |
< |
with Firebird30ClientAPI do |
220 |
> |
with FFirebird30ClientAPI do |
221 |
|
begin |
222 |
|
EndAllTransactions; |
223 |
|
FAttachmentIntf.Detach(StatusIntf); |
238 |
|
procedure TFB30Attachment.DropDatabase; |
239 |
|
begin |
240 |
|
if IsConnected then |
241 |
< |
with Firebird30ClientAPI do |
241 |
> |
with FFirebird30ClientAPI do |
242 |
|
begin |
243 |
|
EndAllTransactions; |
244 |
|
FAttachmentIntf.dropDatabase(StatusIntf); |
251 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
252 |
|
begin |
253 |
|
CheckHandle; |
254 |
< |
Result := TFB30Transaction.Create(self,TPB,DefaultCompletion); |
254 |
> |
Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion); |
255 |
|
end; |
256 |
|
|
257 |
|
function TFB30Attachment.StartTransaction(TPB: ITPB; |
258 |
|
DefaultCompletion: TTransactionCompletion): ITransaction; |
259 |
|
begin |
260 |
|
CheckHandle; |
261 |
< |
Result := TFB30Transaction.Create(self,TPB,DefaultCompletion); |
261 |
> |
Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion); |
262 |
|
end; |
263 |
|
|
264 |
|
procedure TFB30Attachment.ExecImmediate(transaction: ITransaction; sql: AnsiString; |
265 |
|
aSQLDialect: integer); |
266 |
|
begin |
267 |
|
CheckHandle; |
268 |
< |
with Firebird30ClientAPI do |
268 |
> |
with FFirebird30ClientAPI do |
269 |
|
begin |
270 |
|
FAttachmentIntf.execute(StatusIntf,(transaction as TFB30Transaction).TransactionIntf, |
271 |
|
Length(sql),PAnsiChar(sql),aSQLDialect,nil,nil,nil,nil); |
376 |
|
Result := TFB30ArrayMetaData.Create(self,Transaction as TFB30Transaction,tableName,columnName); |
377 |
|
end; |
378 |
|
|
376 |
– |
function TFB30Attachment.GetDBInformation(Requests: array of byte |
377 |
– |
): IDBInformation; |
378 |
– |
var ReqBuffer: PByte; |
379 |
– |
i: integer; |
380 |
– |
begin |
381 |
– |
CheckHandle; |
382 |
– |
if Length(Requests) = 1 then |
383 |
– |
Result := GetDBInformation(Requests[0]) |
384 |
– |
else |
385 |
– |
begin |
386 |
– |
Result := TDBInformation.Create; |
387 |
– |
GetMem(ReqBuffer,Length(Requests)); |
388 |
– |
try |
389 |
– |
for i := 0 to Length(Requests) - 1 do |
390 |
– |
ReqBuffer[i] := Requests[i]; |
391 |
– |
|
392 |
– |
with Firebird30ClientAPI, Result as TDBInformation do |
393 |
– |
begin |
394 |
– |
FAttachmentIntf.getInfo(StatusIntf, Length(Requests), BytePtr(ReqBuffer), |
395 |
– |
getBufSize, BytePtr(Buffer)); |
396 |
– |
Check4DataBaseError; |
397 |
– |
end |
398 |
– |
|
399 |
– |
finally |
400 |
– |
FreeMem(ReqBuffer); |
401 |
– |
end; |
402 |
– |
end; |
403 |
– |
end; |
404 |
– |
|
405 |
– |
function TFB30Attachment.GetDBInformation(Request: byte): IDBInformation; |
406 |
– |
begin |
407 |
– |
CheckHandle; |
408 |
– |
Result := TDBInformation.Create; |
409 |
– |
with Firebird30ClientAPI, Result as TDBInformation do |
410 |
– |
begin |
411 |
– |
FAttachmentIntf.getInfo(StatusIntf, 1, BytePtr(@Request), |
412 |
– |
getBufSize, BytePtr(Buffer)); |
413 |
– |
Check4DataBaseError; |
414 |
– |
end; |
415 |
– |
end; |
416 |
– |
|
379 |
|
end. |
380 |
|
|