25 |
|
* |
26 |
|
*) |
27 |
|
unit FB30Attachment; |
28 |
+ |
{$IFDEF MSWINDOWS} |
29 |
+ |
{$DEFINE WINDOWS} |
30 |
+ |
{$ENDIF} |
31 |
|
|
32 |
|
{$IFDEF FPC} |
33 |
< |
{$mode objfpc}{$H+} |
33 |
> |
{$mode delphi} |
34 |
|
{$interfaces COM} |
35 |
|
{$ENDIF} |
36 |
|
|
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: string; aDPB: IDPB; |
53 |
> |
constructor Create(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
54 |
|
RaiseExceptionOnConnectError: boolean); |
55 |
< |
constructor CreateDatabase(DatabaseName: string; aDPB: IDPB; RaiseExceptionOnError: boolean); |
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; |
72 |
< |
procedure ExecImmediate(transaction: ITransaction; sql: string; aSQLDialect: integer); override; |
73 |
< |
function Prepare(transaction: ITransaction; sql: string; aSQLDialect: integer): IStatement; override; |
74 |
< |
function PrepareWithNamedParameters(transaction: ITransaction; sql: string; |
72 |
> |
procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); override; |
73 |
> |
function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; override; |
74 |
> |
function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString; |
75 |
|
aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; override; |
76 |
|
|
77 |
|
{Events} |
79 |
|
|
80 |
|
{Blob - may use to open existing Blobs. However, ISQLData.AsBlob is preferred} |
81 |
|
|
82 |
< |
function CreateBlob(transaction: ITransaction; RelationName, ColumnName: string; BPB: IBPB=nil): IBlob; overload; |
82 |
> |
function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload; |
83 |
|
function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload; |
84 |
|
function CreateBlob(transaction: ITransaction; SubType: integer; aCharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload; |
85 |
< |
function OpenBlob(transaction: ITransaction; RelationName, ColumnName: string; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; |
86 |
< |
function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; override; overload; |
85 |
> |
function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; |
86 |
> |
function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; override; |
87 |
|
|
88 |
|
{Array} |
89 |
< |
function OpenArray(transaction: ITransaction; RelationName, ColumnName: string; ArrayID: TISC_QUAD): IArray; |
90 |
< |
function CreateArray(transaction: ITransaction; RelationName, ColumnName: string): IArray; overload; |
89 |
> |
function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray; |
90 |
> |
function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload; |
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; |
95 |
+ |
|
96 |
|
|
97 |
|
{Database Information} |
98 |
< |
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: string): IBlobMetaData; |
99 |
< |
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: string): IArrayMetaData; |
87 |
< |
function GetDBInformation(Requests: array of byte): IDBInformation; overload; |
88 |
< |
function GetDBInformation(Request: byte): IDBInformation; overload; |
98 |
> |
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData; |
99 |
> |
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
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: string; 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: string; aDPB: IDPB; |
129 |
> |
constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
130 |
|
RaiseExceptionOnError: boolean); |
131 |
|
var Param: IDPBItem; |
132 |
< |
sql: string; |
132 |
> |
sql: AnsiString; |
133 |
|
IsCreateDB: boolean; |
134 |
|
begin |
135 |
< |
inherited Create(DatabaseName,aDPB,RaiseExceptionOnError); |
136 |
< |
FSQLDialect := 3; |
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(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer; |
165 |
> |
RaiseExceptionOnError: boolean); |
166 |
> |
var IsCreateDB: boolean; |
167 |
> |
begin |
168 |
> |
inherited Create(api,'',nil,RaiseExceptionOnError); |
169 |
> |
FFirebird30ClientAPI := api; |
170 |
> |
FSQLDialect := aSQLDialect; |
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; |
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; |
158 |
– |
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 |
170 |
< |
Param := DPB.Find(isc_dpb_set_db_SQL_dialect); |
171 |
< |
if Param <> nil then |
172 |
< |
FSQLDialect := Param.AsByte; |
173 |
< |
Param := DPB.Find(isc_dpb_lc_ctype); |
174 |
< |
FHasDefaultCharSet := (Param <> nil) and |
175 |
< |
CharSetName2CharSetID(Param.AsString,FCharSetID) and |
176 |
< |
CharSetID2CodePage(FCharSetID,FCodePage) and |
177 |
< |
(FCharSetID > 1); |
178 |
< |
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: string; |
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),PChar(sql),aSQLDialect,nil,nil,nil,nil); |
271 |
> |
Length(sql),PAnsiChar(sql),aSQLDialect,nil,nil,nil,nil); |
272 |
|
Check4DataBaseError; |
273 |
|
end; |
274 |
|
end; |
275 |
|
|
276 |
< |
function TFB30Attachment.Prepare(transaction: ITransaction; sql: string; |
276 |
> |
function TFB30Attachment.Prepare(transaction: ITransaction; sql: AnsiString; |
277 |
|
aSQLDialect: integer): IStatement; |
278 |
|
begin |
279 |
|
CheckHandle; |
281 |
|
end; |
282 |
|
|
283 |
|
function TFB30Attachment.PrepareWithNamedParameters(transaction: ITransaction; |
284 |
< |
sql: string; aSQLDialect: integer; GenerateParamNames: boolean): IStatement; |
284 |
> |
sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean): IStatement; |
285 |
|
begin |
286 |
|
CheckHandle; |
287 |
|
Result := TFB30Statement.CreateWithParameterNames(self,transaction,sql,aSQLDialect, |
295 |
|
end; |
296 |
|
|
297 |
|
function TFB30Attachment.CreateBlob(transaction: ITransaction; RelationName, |
298 |
< |
ColumnName: string; BPB: IBPB): IBlob; |
298 |
> |
ColumnName: AnsiString; BPB: IBPB): IBlob; |
299 |
|
begin |
300 |
|
CheckHandle; |
301 |
|
Result := TFB30Blob.Create(self,transaction as TFB30Transaction, |
317 |
|
end; |
318 |
|
|
319 |
|
function TFB30Attachment.OpenBlob(transaction: ITransaction; RelationName, |
320 |
< |
ColumnName: string; BlobID: TISC_QUAD; BPB: IBPB): IBlob; |
320 |
> |
ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB): IBlob; |
321 |
|
begin |
322 |
|
CheckHandle; |
323 |
|
Result := TFB30Blob.Create(self,transaction as TFB30transaction, |
333 |
|
end; |
334 |
|
|
335 |
|
function TFB30Attachment.OpenArray(transaction: ITransaction; RelationName, |
336 |
< |
ColumnName: string; ArrayID: TISC_QUAD): IArray; |
336 |
> |
ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray; |
337 |
|
begin |
338 |
|
CheckHandle; |
339 |
|
Result := TFB30Array.Create(self,transaction as TFB30Transaction, |
341 |
|
end; |
342 |
|
|
343 |
|
function TFB30Attachment.CreateArray(transaction: ITransaction; RelationName, |
344 |
< |
ColumnName: string): IArray; |
344 |
> |
ColumnName: AnsiString): IArray; |
345 |
|
begin |
346 |
|
CheckHandle; |
347 |
|
Result := TFB30Array.Create(self,transaction as TFB30Transaction, |
355 |
|
Result := TFB30Array.Create(self,transaction as TFB30Transaction,ArrayMetaData); |
356 |
|
end; |
357 |
|
|
358 |
+ |
function TFB30Attachment.CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString; |
359 |
+ |
Scale: integer; size: cardinal; aCharSetID: cardinal; dimensions: cardinal; |
360 |
+ |
bounds: TArrayBounds): IArrayMetaData; |
361 |
+ |
begin |
362 |
+ |
Result := TFB30ArrayMetaData.Create(self,SQLType,tableName,ColumnName,Scale,size,aCharSetID, dimensions,bounds); |
363 |
+ |
end; |
364 |
+ |
|
365 |
|
function TFB30Attachment.GetBlobMetaData(Transaction: ITransaction; tableName, |
366 |
< |
columnName: string): IBlobMetaData; |
366 |
> |
columnName: AnsiString): IBlobMetaData; |
367 |
|
begin |
368 |
|
CheckHandle; |
369 |
|
Result := TFB30BlobMetaData.Create(self,Transaction as TFB30Transaction,tableName,columnName); |
370 |
|
end; |
371 |
|
|
372 |
|
function TFB30Attachment.GetArrayMetaData(Transaction: ITransaction; tableName, |
373 |
< |
columnName: string): IArrayMetaData; |
373 |
> |
columnName: AnsiString): IArrayMetaData; |
374 |
|
begin |
375 |
|
CheckHandle; |
376 |
|
Result := TFB30ArrayMetaData.Create(self,Transaction as TFB30Transaction,tableName,columnName); |
377 |
|
end; |
378 |
|
|
337 |
– |
function TFB30Attachment.GetDBInformation(Requests: array of byte |
338 |
– |
): IDBInformation; |
339 |
– |
var ReqBuffer: PByte; |
340 |
– |
i: integer; |
341 |
– |
begin |
342 |
– |
CheckHandle; |
343 |
– |
if Length(Requests) = 1 then |
344 |
– |
Result := GetDBInformation(Requests[0]) |
345 |
– |
else |
346 |
– |
begin |
347 |
– |
Result := TDBInformation.Create; |
348 |
– |
GetMem(ReqBuffer,Length(Requests)); |
349 |
– |
try |
350 |
– |
for i := 0 to Length(Requests) - 1 do |
351 |
– |
ReqBuffer[i] := Requests[i]; |
352 |
– |
|
353 |
– |
with Firebird30ClientAPI, Result as TDBInformation do |
354 |
– |
begin |
355 |
– |
FAttachmentIntf.getInfo(StatusIntf, Length(Requests), BytePtr(ReqBuffer), |
356 |
– |
getBufSize, BytePtr(Buffer)); |
357 |
– |
Check4DataBaseError; |
358 |
– |
end |
359 |
– |
|
360 |
– |
finally |
361 |
– |
FreeMem(ReqBuffer); |
362 |
– |
end; |
363 |
– |
end; |
364 |
– |
end; |
365 |
– |
|
366 |
– |
function TFB30Attachment.GetDBInformation(Request: byte): IDBInformation; |
367 |
– |
begin |
368 |
– |
CheckHandle; |
369 |
– |
Result := TDBInformation.Create; |
370 |
– |
with Firebird30ClientAPI, Result as TDBInformation do |
371 |
– |
begin |
372 |
– |
FAttachmentIntf.getInfo(StatusIntf, 1, BytePtr(@Request), |
373 |
– |
getBufSize, BytePtr(Buffer)); |
374 |
– |
Check4DataBaseError; |
375 |
– |
end; |
376 |
– |
end; |
377 |
– |
|
379 |
|
end. |
380 |
|
|