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; |
63 |
– |
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 |
170 |
|
end; |
171 |
|
end; |
172 |
|
|
173 |
+ |
procedure TFB30Attachment.SetAttachmentIntf(AValue: Firebird.IAttachment); |
174 |
+ |
begin |
175 |
+ |
if FAttachmentIntf = AValue then Exit; |
176 |
+ |
if FAttachmentIntf <> nil then |
177 |
+ |
try |
178 |
+ |
FAttachmentIntf.release; |
179 |
+ |
except {ignore - forced release} |
180 |
+ |
end; |
181 |
+ |
FOwnsAttachmentHandle := false; |
182 |
+ |
FHasDefaultCharSet := false; |
183 |
+ |
FCodePage := CP_NONE; |
184 |
+ |
FCharSetID := 0; |
185 |
+ |
FTimeZoneServices := nil; |
186 |
+ |
FAttachmentIntf := AValue; |
187 |
+ |
if FAttachmentIntf <> nil then |
188 |
+ |
begin |
189 |
+ |
FAttachmentIntf.AddRef; |
190 |
+ |
GetODSAndConnectionInfo; |
191 |
+ |
end; |
192 |
+ |
end; |
193 |
+ |
|
194 |
|
procedure TFB30Attachment.CheckHandle; |
195 |
|
begin |
196 |
|
if FAttachmentIntf = nil then |
221 |
|
var Param: IDPBItem; |
222 |
|
sql: AnsiString; |
223 |
|
IsCreateDB: boolean; |
224 |
+ |
Intf: Firebird.IAttachment; |
225 |
|
begin |
226 |
|
inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError); |
227 |
|
FFirebird30ClientAPI := api; |
235 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
236 |
|
with FFirebird30ClientAPI do |
237 |
|
begin |
238 |
< |
FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
238 |
> |
Intf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
239 |
|
PAnsiChar(sql),FSQLDialect,@IsCreateDB); |
240 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
241 |
< |
if InErrorState then |
217 |
< |
FAttachmentIntf := nil |
218 |
< |
else |
219 |
< |
if aDPB <> nil then |
220 |
< |
{Connect using known parameters} |
241 |
> |
if not InErrorState then |
242 |
|
begin |
243 |
< |
Disconnect; |
244 |
< |
Connect; |
245 |
< |
end |
246 |
< |
else |
247 |
< |
GetODSAndConnectionInfo; |
243 |
> |
if aDPB <> nil then |
244 |
> |
{Connect using known parameters} |
245 |
> |
begin |
246 |
> |
Intf.Detach(StatusIntf); {releases interface} |
247 |
> |
Check4DataBaseError; |
248 |
> |
Connect; |
249 |
> |
end |
250 |
> |
else |
251 |
> |
AttachmentIntf := Intf; |
252 |
> |
FOwnsAttachmentHandle:= true; |
253 |
> |
end; |
254 |
|
end; |
255 |
|
end; |
256 |
|
|
257 |
|
constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer; |
258 |
|
RaiseExceptionOnError: boolean); |
259 |
|
var IsCreateDB: boolean; |
260 |
+ |
Intf: Firebird.IAttachment; |
261 |
|
begin |
262 |
|
inherited Create(api,'',nil,RaiseExceptionOnError); |
263 |
|
FFirebird30ClientAPI := api; |
264 |
|
FSQLDialect := aSQLDialect; |
265 |
|
with FFirebird30ClientAPI do |
266 |
|
begin |
267 |
< |
FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
267 |
> |
Intf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql), |
268 |
|
PAnsiChar(sql),aSQLDialect,@IsCreateDB); |
269 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
270 |
|
if InErrorState then |
271 |
< |
FAttachmentIntf := nil; |
271 |
> |
Exit; |
272 |
|
end; |
273 |
< |
GetODSAndConnectionInfo; |
273 |
> |
AttachmentIntf := Intf; |
274 |
> |
FOwnsAttachmentHandle:= true; |
275 |
|
ExtractConnectString(sql,FDatabaseName); |
276 |
|
DPBFromCreateSQL(sql); |
277 |
|
end; |
278 |
|
|
279 |
< |
destructor TFB30Attachment.Destroy; |
279 |
> |
constructor TFB30Attachment.Create(api: TFB30ClientAPI; |
280 |
> |
attachment: Firebird.IAttachment; aDatabaseName: AnsiString); |
281 |
|
begin |
282 |
< |
inherited Destroy; |
283 |
< |
if assigned(FAttachmentIntf) then |
284 |
< |
FAttachmentIntf.release; |
282 |
> |
inherited Create(api,aDatabaseName,nil,false); |
283 |
> |
FFirebird30ClientAPI := api; |
284 |
> |
AttachmentIntf := attachment; |
285 |
|
end; |
286 |
|
|
287 |
|
function TFB30Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; |
296 |
|
end; |
297 |
|
|
298 |
|
procedure TFB30Attachment.Connect; |
299 |
+ |
var Intf: Firebird.IAttachment; |
300 |
|
begin |
301 |
|
with FFirebird30ClientAPI do |
302 |
|
begin |
303 |
< |
FAttachmentIntf := ProviderIntf.attachDatabase(StatusIntf,PAnsiChar(FDatabaseName), |
303 |
> |
Intf := ProviderIntf.attachDatabase(StatusIntf,PAnsiChar(FDatabaseName), |
304 |
|
(DPB as TDPB).getDataLength, |
305 |
|
BytePtr((DPB as TDPB).getBuffer)); |
306 |
|
if FRaiseExceptionOnConnectError then Check4DataBaseError; |
307 |
< |
if InErrorState then |
308 |
< |
FAttachmentIntf := nil |
309 |
< |
else |
310 |
< |
GetODSAndConnectionInfo; |
311 |
< |
|
307 |
> |
if not InErrorState then |
308 |
> |
begin |
309 |
> |
AttachmentIntf := Intf; |
310 |
> |
FOwnsAttachmentHandle := true; |
311 |
> |
end; |
312 |
|
end; |
313 |
|
end; |
314 |
|
|
316 |
|
begin |
317 |
|
inherited Disconnect(Force); |
318 |
|
if IsConnected then |
319 |
+ |
begin |
320 |
+ |
if FOwnsAttachmentHandle then |
321 |
|
with FFirebird30ClientAPI do |
322 |
|
begin |
323 |
|
EndAllTransactions; |
324 |
|
FAttachmentIntf.Detach(StatusIntf); |
325 |
|
if not Force and InErrorState then |
326 |
|
IBDataBaseError; |
294 |
– |
FAttachmentIntf := nil; |
295 |
– |
FHasDefaultCharSet := false; |
296 |
– |
FCodePage := CP_NONE; |
297 |
– |
FCharSetID := 0; |
298 |
– |
FTimeZoneServices := nil; |
327 |
|
end; |
328 |
+ |
AttachmentIntf := nil; |
329 |
+ |
end; |
330 |
|
end; |
331 |
|
|
332 |
|
function TFB30Attachment.IsConnected: boolean; |
337 |
|
procedure TFB30Attachment.DropDatabase; |
338 |
|
begin |
339 |
|
if IsConnected then |
340 |
+ |
begin |
341 |
+ |
if not FOwnsAttachmentHandle then |
342 |
+ |
IBError(ibxeCantDropAcquiredDB,[nil]); |
343 |
|
with FFirebird30ClientAPI do |
344 |
|
begin |
345 |
|
EndAllTransactions; |
346 |
|
EndSession(false); |
347 |
|
FAttachmentIntf.dropDatabase(StatusIntf); |
348 |
|
Check4DataBaseError; |
316 |
– |
FAttachmentIntf := nil; |
349 |
|
end; |
350 |
+ |
AttachmentIntf := nil; |
351 |
+ |
end; |
352 |
|
end; |
353 |
|
|
354 |
|
function TFB30Attachment.StartTransaction(TPB: array of byte; |