394 |
|
end; |
395 |
|
|
396 |
|
TTransactionEndEvent = procedure(Sender:TObject; Action: TTransactionAction) of object; |
397 |
+ |
TBeforeDatabaseConnectEvent = procedure (Sender: TObject; DBParams: TStrings; |
398 |
+ |
var DBName: string) of object; |
399 |
|
|
400 |
|
{ TIBBase } |
401 |
|
|
404 |
|
connections. } |
405 |
|
TIBBase = class(TObject) |
406 |
|
protected |
407 |
+ |
FBeforeDatabaseConnect: TBeforeDatabaseConnectEvent; |
408 |
|
FDatabase: TIBDatabase; |
409 |
|
FIndexInDatabase: Integer; |
410 |
|
FTransaction: TIBTransaction; |
418 |
|
FAfterTransactionEnd: TNotifyEvent; |
419 |
|
FOnTransactionFree: TNotifyEvent; |
420 |
|
|
421 |
+ |
procedure DoBeforeDatabaseConnect(DBParams: TStrings; |
422 |
+ |
var DBName: string); virtual; |
423 |
|
procedure DoAfterDatabaseConnect; virtual; |
424 |
|
procedure DoBeforeDatabaseDisconnect; virtual; |
425 |
|
procedure DoAfterDatabaseDisconnect; virtual; |
443 |
|
procedure DoAfterPost(Sender: TObject); virtual; |
444 |
|
function GetCharSetSize(CharSetID: integer): integer; |
445 |
|
public |
446 |
+ |
property BeforeDatabaseConnect: TBeforeDatabaseConnectEvent read FBeforeDatabaseConnect |
447 |
+ |
write FBeforeDatabaseConnect; |
448 |
|
property AfterDatabaseConnect: TNotifyEvent read FAfterDatabaseConnect |
449 |
|
write FAfterDatabaseConnect; |
450 |
|
property BeforeDatabaseDisconnect: TNotifyEvent read FBeforeDatabaseDisconnect |
977 |
|
DPB: String; |
978 |
|
TempDBParams: TStrings; |
979 |
|
I: integer; |
980 |
< |
|
980 |
> |
aDBName: string; |
981 |
|
begin |
982 |
|
CheckInactive; |
983 |
|
CheckDatabaseName; |
989 |
|
{ Use builtin login prompt if requested } |
990 |
|
if (LoginPrompt or (csDesigning in ComponentState)) and not Login then |
991 |
|
IBError(ibxeOperationCancelled, [nil]); |
992 |
< |
{ Generate a new DPB if necessary } |
993 |
< |
if (FDBParamsChanged) then |
994 |
< |
begin |
995 |
< |
FDBParamsChanged := False; |
996 |
< |
if (not LoginPrompt and not (csDesigning in ComponentState)) or (FHiddenPassword = '') then |
997 |
< |
GenerateDPB(FDBParams, DPB, FDPBLength) |
998 |
< |
else |
999 |
< |
begin |
1000 |
< |
TempDBParams := TStringList.Create; |
1001 |
< |
try |
1002 |
< |
TempDBParams.Assign(FDBParams); |
1003 |
< |
TempDBParams.Add('password=' + FHiddenPassword); |
1004 |
< |
GenerateDPB(TempDBParams, DPB, FDPBLength); |
1005 |
< |
finally |
1006 |
< |
TempDBParams.Free; |
1007 |
< |
end; |
1008 |
< |
end; |
1009 |
< |
IBAlloc(FDPB, 0, FDPBLength); |
1010 |
< |
Move(DPB[1], FDPB[0], FDPBLength); |
992 |
> |
|
993 |
> |
TempDBParams := TStringList.Create; |
994 |
> |
try |
995 |
> |
TempDBParams.Assign(FDBParams); |
996 |
> |
aDBName := FDBName; |
997 |
> |
{Opportuning to override defaults} |
998 |
> |
for i := 0 to FSQLObjects.Count - 1 do |
999 |
> |
begin |
1000 |
> |
if FSQLObjects[i] <> nil then |
1001 |
> |
SQLObjects[i].DoBeforeDatabaseConnect(TempDBParams,aDBName); |
1002 |
> |
end; |
1003 |
> |
|
1004 |
> |
{ Generate a new DPB if necessary } |
1005 |
> |
if (FDBParamsChanged or (TempDBParams.Text <> FDBParams.Text)) then |
1006 |
> |
begin |
1007 |
> |
FDBParamsChanged := False; |
1008 |
> |
if (not LoginPrompt and not (csDesigning in ComponentState)) or (FHiddenPassword = '') then |
1009 |
> |
GenerateDPB(TempDBParams, DPB, FDPBLength) |
1010 |
> |
else |
1011 |
> |
begin |
1012 |
> |
TempDBParams.Add('password=' + FHiddenPassword); |
1013 |
> |
GenerateDPB(TempDBParams, DPB, FDPBLength); |
1014 |
> |
end; |
1015 |
> |
IBAlloc(FDPB, 0, FDPBLength); |
1016 |
> |
Move(DPB[1], FDPB[0], FDPBLength); |
1017 |
> |
end; |
1018 |
> |
finally |
1019 |
> |
TempDBParams.Free; |
1020 |
|
end; |
1021 |
< |
if Call(isc_attach_database(StatusVector, Length(FDBName), |
1022 |
< |
PChar(FDBName), @FHandle, |
1021 |
> |
if Call(isc_attach_database(StatusVector, Length(aDBName), |
1022 |
> |
PChar(aDBName), @FHandle, |
1023 |
|
FDPBLength, FDPB), False) > 0 then |
1024 |
|
begin |
1025 |
|
FHandle := nil; |
1026 |
|
IBDataBaseError; |
1027 |
|
end; |
1028 |
+ |
if not (csDesigning in ComponentState) then |
1029 |
+ |
FDBName := aDBName; {Synchronise at run time} |
1030 |
|
FDBSQLDialect := GetDBSQLDialect; |
1031 |
|
ValidateClientSQLDialect; |
1032 |
|
for i := 0 to FSQLObjects.Count - 1 do |
2021 |
|
result := @FTransaction.Handle; |
2022 |
|
end; |
2023 |
|
|
2024 |
+ |
procedure TIBBase.DoBeforeDatabaseConnect(DBParams: TStrings; var DBName: string |
2025 |
+ |
); |
2026 |
+ |
begin |
2027 |
+ |
if assigned(FBeforeDatabaseConnect) then |
2028 |
+ |
BeforeDatabaseConnect(self,DBParams,DBName); |
2029 |
+ |
end; |
2030 |
+ |
|
2031 |
|
procedure TIBBase.DoAfterDatabaseConnect; |
2032 |
|
begin |
2033 |
|
if assigned(FAfterDatabaseConnect) then |