50 |
|
FFirebird30ClientAPI: TFB30ClientAPI; |
51 |
|
FTimeZoneServices: ITimeZoneServices; |
52 |
|
FUsingRemoteICU: boolean; |
53 |
+ |
FOwnsAttachmentHandle: boolean; |
54 |
+ |
procedure SetAttachmentIntf(AValue: Firebird.IAttachment); |
55 |
|
procedure SetUseRemoteICU(aValue: boolean); |
56 |
|
protected |
57 |
|
procedure CheckHandle; override; |
58 |
+ |
function GetAttachment: IAttachment; override; |
59 |
|
public |
60 |
|
constructor Create(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
61 |
< |
RaiseExceptionOnConnectError: boolean); |
61 |
> |
RaiseExceptionOnConnectError: boolean); overload; |
62 |
> |
constructor Create(api: TFB30ClientAPI; |
63 |
> |
attachment: Firebird.IAttachment; aDatabaseName: AnsiString); overload; |
64 |
|
constructor CreateDatabase(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean); overload; |
65 |
|
constructor CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer; |
66 |
|
RaiseExceptionOnError: boolean); overload; |
62 |
– |
destructor Destroy; override; |
67 |
|
function GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; |
68 |
|
override; |
69 |
< |
property AttachmentIntf: Firebird.IAttachment read FAttachmentIntf; |
69 |
> |
property AttachmentIntf: Firebird.IAttachment read FAttachmentIntf write SetAttachmentIntf; |
70 |
|
property Firebird30ClientAPI: TFB30ClientAPI read FFirebird30ClientAPI; |
71 |
|
|
72 |
|
public |
75 |
|
procedure Disconnect(Force: boolean=false); override; |
76 |
|
function IsConnected: boolean; override; |
77 |
|
procedure DropDatabase; |
78 |
< |
function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
79 |
< |
function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
78 |
> |
function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion; aName: AnsiString=''): ITransaction; override; |
79 |
> |
function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion; aName: AnsiString=''): ITransaction; override; |
80 |
|
procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); override; |
81 |
|
function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer; CursorName: AnsiString=''): IStatement; override; |
82 |
|
function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString; |
141 |
|
end; |
142 |
|
|
143 |
|
procedure TVersionCallback.callback(status: Firebird.IStatus; text: PAnsiChar); |
144 |
< |
var StatusObj: TFB30StatusObject; |
144 |
> |
var aStatus: IStatus; |
145 |
|
begin |
146 |
< |
if ((status.getState and status.STATE_ERRORS) <> 0) then |
147 |
< |
begin |
148 |
< |
StatusObj := TFB30StatusObject.Create(FFirebirdClientAPI,status); |
145 |
< |
try |
146 |
< |
raise EIBInterBaseError.Create(StatusObj); |
147 |
< |
finally |
148 |
< |
StatusObj.Free; |
149 |
< |
end; |
150 |
< |
end; |
146 |
> |
aStatus := TFB30Status.Create(FFirebirdClientAPI,status); |
147 |
> |
if aStatus.InErrorState then |
148 |
> |
raise EIBInterBaseError.Create(aStatus); |
149 |
|
FOutput.Add(text); |
150 |
|
end; |
151 |
|
|
164 |
|
end; |
165 |
|
end; |
166 |
|
|
167 |
+ |
procedure TFB30Attachment.SetAttachmentIntf(AValue: Firebird.IAttachment); |
168 |
+ |
begin |
169 |
+ |
if FAttachmentIntf = AValue then Exit; |
170 |
+ |
if FAttachmentIntf <> nil then |
171 |
+ |
try |
172 |
+ |
FAttachmentIntf.release; |
173 |
+ |
except {ignore - forced release} |
174 |
+ |
end; |
175 |
+ |
FOwnsAttachmentHandle := false; |
176 |
+ |
ClearCachedInfo; |
177 |
+ |
FTimeZoneServices := nil; |
178 |
+ |
FAttachmentIntf := AValue; |
179 |
+ |
if FAttachmentIntf <> nil then |
180 |
+ |
FAttachmentIntf.AddRef; |
181 |
+ |
end; |
182 |
+ |
|
183 |
|
procedure TFB30Attachment.CheckHandle; |
184 |
|
begin |
185 |
|
if FAttachmentIntf = nil then |
186 |
|
IBError(ibxeDatabaseClosed,[nil]); |
187 |
|
end; |
188 |
|
|
189 |
+ |
function TFB30Attachment.GetAttachment: IAttachment; |
190 |
+ |
begin |
191 |
+ |
Result := self; |
192 |
+ |
end; |
193 |
+ |
|
194 |
|
constructor TFB30Attachment.Create(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; |
195 |
|
RaiseExceptionOnConnectError: boolean); |
196 |
|
begin |
210 |
|
var Param: IDPBItem; |
211 |
|
sql: AnsiString; |
212 |
|
IsCreateDB: boolean; |
213 |
+ |
Intf: Firebird.IAttachment; |
214 |
|
begin |
215 |
|
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError); |
216 |
|
FFirebird30ClientAPI := api; |
219 |
|
begin |
220 |
|
Param := aDPB.Find(isc_dpb_set_db_SQL_dialect); |
221 |
|
if Param <> nil then |
222 |
< |
FSQLDialect := Param.AsByte; |
222 |
> |
SetSQLDialect(Param.AsByte); |
223 |
|
end; |
224 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
225 |
|
with FFirebird30ClientAPI do |
226 |
|
begin |
227 |
< |
FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
228 |
< |
PAnsiChar(sql),FSQLDialect,@IsCreateDB); |
227 |
> |
Intf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
228 |
> |
PAnsiChar(sql),SQLDialect,@IsCreateDB); |
229 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
230 |
< |
if InErrorState then |
211 |
< |
FAttachmentIntf := nil |
212 |
< |
else |
213 |
< |
if aDPB <> nil then |
214 |
< |
{Connect using known parameters} |
230 |
> |
if not InErrorState then |
231 |
|
begin |
232 |
< |
Disconnect; |
233 |
< |
Connect; |
234 |
< |
end |
235 |
< |
else |
236 |
< |
GetODSAndConnectionInfo; |
232 |
> |
if aDPB <> nil then |
233 |
> |
{Connect using known parameters} |
234 |
> |
begin |
235 |
> |
Intf.Detach(StatusIntf); {releases interface} |
236 |
> |
Check4DataBaseError; |
237 |
> |
Connect; |
238 |
> |
end |
239 |
> |
else |
240 |
> |
AttachmentIntf := Intf; |
241 |
> |
FOwnsAttachmentHandle:= true; |
242 |
> |
end; |
243 |
|
end; |
244 |
|
end; |
245 |
|
|
246 |
|
constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer; |
247 |
|
RaiseExceptionOnError: boolean); |
248 |
|
var IsCreateDB: boolean; |
249 |
+ |
Intf: Firebird.IAttachment; |
250 |
|
begin |
251 |
|
inherited Create(api,'',nil,RaiseExceptionOnError); |
252 |
|
FFirebird30ClientAPI := api; |
253 |
< |
FSQLDialect := aSQLDialect; |
253 |
> |
SetSQLDialect(aSQLDialect); |
254 |
|
with FFirebird30ClientAPI do |
255 |
|
begin |
256 |
< |
FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
256 |
> |
Intf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
257 |
|
PAnsiChar(sql),aSQLDialect,@IsCreateDB); |
258 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
259 |
|
if InErrorState then |
260 |
< |
FAttachmentIntf := nil; |
260 |
> |
Exit; |
261 |
|
end; |
262 |
< |
GetODSAndConnectionInfo; |
262 |
> |
AttachmentIntf := Intf; |
263 |
> |
FOwnsAttachmentHandle:= true; |
264 |
|
ExtractConnectString(sql,FDatabaseName); |
265 |
|
DPBFromCreateSQL(sql); |
266 |
|
end; |
267 |
|
|
268 |
< |
destructor TFB30Attachment.Destroy; |
268 |
> |
constructor TFB30Attachment.Create(api: TFB30ClientAPI; |
269 |
> |
attachment: Firebird.IAttachment; aDatabaseName: AnsiString); |
270 |
|
begin |
271 |
< |
inherited Destroy; |
272 |
< |
if assigned(FAttachmentIntf) then |
273 |
< |
FAttachmentIntf.release; |
271 |
> |
inherited Create(api,aDatabaseName,nil,false); |
272 |
> |
FFirebird30ClientAPI := api; |
273 |
> |
AttachmentIntf := attachment; |
274 |
|
end; |
275 |
|
|
276 |
|
function TFB30Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; |
285 |
|
end; |
286 |
|
|
287 |
|
procedure TFB30Attachment.Connect; |
288 |
+ |
var Intf: Firebird.IAttachment; |
289 |
|
begin |
290 |
|
with FFirebird30ClientAPI do |
291 |
|
begin |
292 |
< |
FAttachmentIntf := ProviderIntf.attachDatabase(StatusIntf,PAnsiChar(FDatabaseName), |
292 |
> |
Intf := ProviderIntf.attachDatabase(StatusIntf,PAnsiChar(FDatabaseName), |
293 |
|
(DPB as TDPB).getDataLength, |
294 |
|
BytePtr((DPB as TDPB).getBuffer)); |
295 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
296 |
< |
if InErrorState then |
297 |
< |
FAttachmentIntf := nil |
298 |
< |
else |
299 |
< |
GetODSAndConnectionInfo; |
300 |
< |
|
296 |
> |
if not InErrorState then |
297 |
> |
begin |
298 |
> |
AttachmentIntf := Intf; |
299 |
> |
FOwnsAttachmentHandle := true; |
300 |
> |
end; |
301 |
|
end; |
302 |
|
end; |
303 |
|
|
304 |
|
procedure TFB30Attachment.Disconnect(Force: boolean); |
305 |
|
begin |
306 |
|
if IsConnected then |
307 |
+ |
begin |
308 |
+ |
EndAllTransactions; |
309 |
+ |
if FOwnsAttachmentHandle then |
310 |
|
with FFirebird30ClientAPI do |
311 |
|
begin |
283 |
– |
EndAllTransactions; |
312 |
|
FAttachmentIntf.Detach(StatusIntf); |
313 |
|
if not Force and InErrorState then |
314 |
|
IBDataBaseError; |
287 |
– |
FAttachmentIntf := nil; |
288 |
– |
FHasDefaultCharSet := false; |
289 |
– |
FCodePage := CP_NONE; |
290 |
– |
FCharSetID := 0; |
291 |
– |
FTimeZoneServices := nil; |
315 |
|
end; |
316 |
+ |
AttachmentIntf := nil; |
317 |
+ |
end; |
318 |
+ |
inherited Disconnect(Force); |
319 |
|
end; |
320 |
|
|
321 |
|
function TFB30Attachment.IsConnected: boolean; |
326 |
|
procedure TFB30Attachment.DropDatabase; |
327 |
|
begin |
328 |
|
if IsConnected then |
329 |
+ |
begin |
330 |
+ |
if not FOwnsAttachmentHandle then |
331 |
+ |
IBError(ibxeCantDropAcquiredDB,[nil]); |
332 |
|
with FFirebird30ClientAPI do |
333 |
|
begin |
334 |
|
EndAllTransactions; |
335 |
+ |
EndSession(false); |
336 |
|
FAttachmentIntf.dropDatabase(StatusIntf); |
337 |
|
Check4DataBaseError; |
308 |
– |
FAttachmentIntf := nil; |
338 |
|
end; |
339 |
+ |
AttachmentIntf := nil; |
340 |
+ |
end; |
341 |
|
end; |
342 |
|
|
343 |
|
function TFB30Attachment.StartTransaction(TPB: array of byte; |
344 |
< |
DefaultCompletion: TTransactionCompletion): ITransaction; |
344 |
> |
DefaultCompletion: TTransactionCompletion; aName: AnsiString): ITransaction; |
345 |
|
begin |
346 |
|
CheckHandle; |
347 |
< |
Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion); |
347 |
> |
Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion, aName); |
348 |
|
end; |
349 |
|
|
350 |
|
function TFB30Attachment.StartTransaction(TPB: ITPB; |
351 |
< |
DefaultCompletion: TTransactionCompletion): ITransaction; |
351 |
> |
DefaultCompletion: TTransactionCompletion; aName: AnsiString): ITransaction; |
352 |
|
begin |
353 |
|
CheckHandle; |
354 |
< |
Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion); |
354 |
> |
Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion,aName); |
355 |
|
end; |
356 |
|
|
357 |
|
procedure TFB30Attachment.ExecImmediate(transaction: ITransaction; sql: AnsiString; |
359 |
|
begin |
360 |
|
CheckHandle; |
361 |
|
with FFirebird30ClientAPI do |
362 |
< |
begin |
362 |
> |
try |
363 |
|
FAttachmentIntf.execute(StatusIntf,(transaction as TFB30Transaction).TransactionIntf, |
364 |
|
Length(sql),PAnsiChar(sql),aSQLDialect,nil,nil,nil,nil); |
365 |
|
Check4DataBaseError; |
366 |
+ |
finally |
367 |
+ |
if JournalingActive and |
368 |
+ |
((joReadOnlyQueries in GetJournalOptions) or |
369 |
+ |
(joModifyQueries in GetJournalOptions)) then |
370 |
+ |
ExecImmediateJnl(sql,transaction); |
371 |
|
end; |
372 |
|
end; |
373 |
|
|