279 |
|
|
280 |
|
TIBTransaction = class(TComponent) |
281 |
|
private |
282 |
+ |
FAfterTransactionEnd: TNotifyEvent; |
283 |
+ |
FBeforeTransactionEnd: TNotifyEvent; |
284 |
|
FIBLoaded: Boolean; |
285 |
|
FCanTimeout : Boolean; |
286 |
|
FDatabases : TList; |
297 |
|
FTRParams : TStrings; |
298 |
|
FTRParamsChanged : Boolean; |
299 |
|
FInEndTransaction : boolean; |
300 |
+ |
FEndAction : TTransactionAction; |
301 |
+ |
procedure DoBeforeTransactionEnd; |
302 |
+ |
procedure DoAfterTransactionEnd; |
303 |
|
procedure EnsureNotInTransaction; |
304 |
|
procedure EndTransaction(Action: TTransactionAction; Force: Boolean); |
305 |
|
function GetDatabase(Index: Integer): TIBDatabase; |
341 |
|
function AddDatabase(db: TIBDatabase): Integer; |
342 |
|
function FindDatabase(db: TIBDatabase): Integer; |
343 |
|
function FindDefaultDatabase: TIBDatabase; |
344 |
+ |
function GetEndAction: TTransactionAction; |
345 |
|
procedure RemoveDatabase(Idx: Integer); |
346 |
|
procedure RemoveDatabases; |
347 |
|
procedure CheckDatabasesInList; |
363 |
|
property DefaultAction: TTransactionAction read FDefaultAction write SetDefaultAction default taCommit; |
364 |
|
property Params: TStrings read FTRParams write SetTRParams; |
365 |
|
property OnIdleTimer: TNotifyEvent read FOnIdleTimer write FOnIdleTimer; |
366 |
+ |
property BeforeTransactionEnd: TNotifyEvent read FBeforeTransactionEnd |
367 |
+ |
write FBeforeTransactionEnd; |
368 |
+ |
property AfterTransactionEnd: TNotifyEvent read FAfterTransactionEnd |
369 |
+ |
write FAfterTransactionEnd; |
370 |
|
end; |
371 |
|
|
372 |
|
{ TIBBase } |
436 |
|
|
437 |
|
{ TIBDatabase } |
438 |
|
|
439 |
< |
constructor TIBDatabase.Create(AOwner: TComponent); |
439 |
> |
constructor TIBDataBase.Create(AOwner: TComponent); |
440 |
|
{$ifdef WINDOWS} |
441 |
|
var acp: uint; |
442 |
|
{$endif} |
482 |
|
CheckStreamConnect; |
483 |
|
end; |
484 |
|
|
485 |
< |
destructor TIBDatabase.Destroy; |
485 |
> |
destructor TIBDataBase.Destroy; |
486 |
|
var |
487 |
|
i: Integer; |
488 |
|
begin |
508 |
|
inherited Destroy; |
509 |
|
end; |
510 |
|
|
511 |
< |
function TIBDatabase.Call(ErrCode: ISC_STATUS; |
512 |
< |
RaiseError: Boolean): ISC_STATUS; |
511 |
> |
function TIBDataBase.Call(ErrCode: ISC_STATUS; RaiseError: Boolean |
512 |
> |
): ISC_STATUS; |
513 |
|
begin |
514 |
|
result := ErrCode; |
515 |
|
FCanTimeout := False; |
517 |
|
IBDataBaseError; |
518 |
|
end; |
519 |
|
|
520 |
< |
procedure TIBDatabase.CheckActive; |
520 |
> |
procedure TIBDataBase.CheckActive; |
521 |
|
begin |
522 |
|
if StreamedConnected and (not Connected) then |
523 |
|
Loaded; |
525 |
|
IBError(ibxeDatabaseClosed, [nil]); |
526 |
|
end; |
527 |
|
|
528 |
< |
procedure TIBDatabase.EnsureInactive; |
528 |
> |
procedure TIBDataBase.EnsureInactive; |
529 |
|
begin |
530 |
|
if csDesigning in ComponentState then |
531 |
|
begin |
534 |
|
end |
535 |
|
end; |
536 |
|
|
537 |
< |
procedure TIBDatabase.CheckInactive; |
537 |
> |
procedure TIBDataBase.CheckInactive; |
538 |
|
begin |
539 |
|
if FHandle <> nil then |
540 |
|
IBError(ibxeDatabaseOpen, [nil]); |
541 |
|
end; |
542 |
|
|
543 |
< |
procedure TIBDatabase.CheckDatabaseName; |
543 |
> |
procedure TIBDataBase.CheckDatabaseName; |
544 |
|
begin |
545 |
|
if (FDBName = '') then |
546 |
|
IBError(ibxeDatabaseNameMissing, [nil]); |
547 |
|
end; |
548 |
|
|
549 |
< |
function TIBDatabase.AddSQLObject(ds: TIBBase): Integer; |
549 |
> |
function TIBDataBase.AddSQLObject(ds: TIBBase): Integer; |
550 |
|
begin |
551 |
|
result := 0; |
552 |
|
if (ds.Owner is TIBCustomDataSet) then |
559 |
|
FSQLObjects[result] := ds; |
560 |
|
end; |
561 |
|
|
562 |
< |
function TIBDatabase.AddTransaction(TR: TIBTransaction): Integer; |
562 |
> |
function TIBDataBase.AddTransaction(TR: TIBTransaction): Integer; |
563 |
|
begin |
564 |
|
result := FindTransaction(TR); |
565 |
|
if result <> -1 then |
576 |
|
FTransactions[result] := TR; |
577 |
|
end; |
578 |
|
|
579 |
< |
procedure TIBDatabase.DoDisconnect; |
579 |
> |
procedure TIBDataBase.DoDisconnect; |
580 |
|
begin |
581 |
|
if Connected then |
582 |
|
InternalClose(False); |
583 |
|
FDBSQLDialect := 1; |
584 |
|
end; |
585 |
|
|
586 |
< |
procedure TIBDatabase.CreateDatabase; |
586 |
> |
procedure TIBDataBase.CreateDatabase; |
587 |
|
var |
588 |
|
tr_handle: TISC_TR_HANDLE; |
589 |
|
begin |
596 |
|
True); |
597 |
|
end; |
598 |
|
|
599 |
< |
procedure TIBDatabase.DropDatabase; |
599 |
> |
procedure TIBDataBase.DropDatabase; |
600 |
|
begin |
601 |
|
CheckActive; |
602 |
|
Call(isc_drop_database(StatusVector, @FHandle), True); |
603 |
|
end; |
604 |
|
|
605 |
< |
procedure TIBDatabase.DBParamsChange(Sender: TObject); |
605 |
> |
procedure TIBDataBase.DBParamsChange(Sender: TObject); |
606 |
|
begin |
607 |
|
FDBParamsChanged := True; |
608 |
|
end; |
609 |
|
|
610 |
< |
procedure TIBDatabase.DBParamsChanging(Sender: TObject); |
610 |
> |
procedure TIBDataBase.DBParamsChanging(Sender: TObject); |
611 |
|
begin |
612 |
|
EnsureInactive; |
613 |
|
CheckInactive; |
614 |
|
end; |
615 |
|
|
616 |
< |
function TIBDatabase.FindTransaction(TR: TIBTransaction): Integer; |
616 |
> |
function TIBDataBase.FindTransaction(TR: TIBTransaction): Integer; |
617 |
|
var |
618 |
|
i: Integer; |
619 |
|
begin |
626 |
|
end; |
627 |
|
end; |
628 |
|
|
629 |
< |
function TIBDatabase.FindDefaultTransaction(): TIBTransaction; |
629 |
> |
function TIBDataBase.FindDefaultTransaction: TIBTransaction; |
630 |
|
var |
631 |
|
i: Integer; |
632 |
|
begin |
644 |
|
end; |
645 |
|
end; |
646 |
|
|
647 |
< |
procedure TIBDatabase.ForceClose; |
647 |
> |
procedure TIBDataBase.ForceClose; |
648 |
|
begin |
649 |
|
if Connected then |
650 |
|
InternalClose(True); |
651 |
|
end; |
652 |
|
|
653 |
< |
function TIBDatabase.GetConnected: Boolean; |
653 |
> |
function TIBDataBase.GetConnected: Boolean; |
654 |
|
begin |
655 |
|
result := FHandle <> nil; |
656 |
|
end; |
657 |
|
|
658 |
< |
function TIBDatabase.GetSQLObject(Index: Integer): TIBBase; |
658 |
> |
function TIBDataBase.GetSQLObject(Index: Integer): TIBBase; |
659 |
|
begin |
660 |
|
result := FSQLObjects[Index]; |
661 |
|
end; |
662 |
|
|
663 |
< |
function TIBDatabase.GetSQLObjectCount: Integer; |
663 |
> |
function TIBDataBase.GetSQLObjectCount: Integer; |
664 |
|
var |
665 |
|
i: Integer; |
666 |
|
begin |
669 |
|
Inc(result); |
670 |
|
end; |
671 |
|
|
672 |
< |
function TIBDatabase.GetDBParamByDPB(const Idx: Integer): String; |
672 |
> |
function TIBDataBase.GetDBParamByDPB( const Idx: Integer): String; |
673 |
|
var |
674 |
|
ConstIdx, EqualsIdx: Integer; |
675 |
|
begin |
692 |
|
result := ''; |
693 |
|
end; |
694 |
|
|
695 |
< |
function TIBDatabase.GetIdleTimer: Integer; |
695 |
> |
function TIBDataBase.GetIdleTimer: Integer; |
696 |
|
begin |
697 |
|
result := FTimer.Interval; |
698 |
|
end; |
699 |
|
|
700 |
< |
function TIBDatabase.GetTransaction(Index: Integer): TIBTransaction; |
700 |
> |
function TIBDataBase.GetTransaction(Index: Integer): TIBTransaction; |
701 |
|
begin |
702 |
|
result := FTransactions[Index]; |
703 |
|
end; |
704 |
|
|
705 |
< |
function TIBDatabase.GetTransactionCount: Integer; |
705 |
> |
function TIBDataBase.GetTransactionCount: Integer; |
706 |
|
var |
707 |
|
i: Integer; |
708 |
|
begin |
712 |
|
Inc(result); |
713 |
|
end; |
714 |
|
|
715 |
< |
function TIBDatabase.IndexOfDBConst(st: String): Integer; |
715 |
> |
function TIBDataBase.IndexOfDBConst(st: String): Integer; |
716 |
|
var |
717 |
|
i, pos_of_str: Integer; |
718 |
|
begin |
728 |
|
end; |
729 |
|
end; |
730 |
|
|
731 |
< |
procedure TIBDatabase.InternalClose(Force: Boolean); |
731 |
> |
procedure TIBDataBase.InternalClose(Force: Boolean); |
732 |
|
var |
733 |
|
i: Integer; |
734 |
|
begin |
807 |
|
end; |
808 |
|
end; |
809 |
|
|
810 |
< |
procedure TIBDatabase.Notification( AComponent: TComponent; |
811 |
< |
Operation: TOperation); |
810 |
> |
procedure TIBDataBase.Notification(AComponent: TComponent; |
811 |
> |
Operation: TOperation); |
812 |
|
var |
813 |
|
i: Integer; |
814 |
|
begin |
822 |
|
end; |
823 |
|
end; |
824 |
|
|
825 |
< |
function TIBDatabase.Login: Boolean; |
825 |
> |
function TIBDataBase.Login: Boolean; |
826 |
|
var |
827 |
|
IndexOfUser, IndexOfPassword: Integer; |
828 |
|
Username, Password, OldPassword: String; |
901 |
|
end; |
902 |
|
end; |
903 |
|
|
904 |
< |
procedure TIBDatabase.DoConnect; |
904 |
> |
procedure TIBDataBase.DoConnect; |
905 |
|
var |
906 |
|
DPB: String; |
907 |
|
TempDBParams: TStrings; |
956 |
|
MonitorHook.DBConnect(Self); |
957 |
|
end; |
958 |
|
|
959 |
< |
procedure TIBDatabase.RemoveSQLObject(Idx: Integer); |
959 |
> |
procedure TIBDataBase.RemoveSQLObject(Idx: Integer); |
960 |
|
var |
961 |
|
ds: TIBBase; |
962 |
|
begin |
970 |
|
end; |
971 |
|
end; |
972 |
|
|
973 |
< |
procedure TIBDatabase.RemoveSQLObjects; |
973 |
> |
procedure TIBDataBase.RemoveSQLObjects; |
974 |
|
var |
975 |
|
i: Integer; |
976 |
|
begin |
982 |
|
end; |
983 |
|
end; |
984 |
|
|
985 |
< |
procedure TIBDatabase.RemoveTransaction(Idx: Integer); |
985 |
> |
procedure TIBDataBase.RemoveTransaction(Idx: Integer); |
986 |
|
var |
987 |
|
TR: TIBTransaction; |
988 |
|
begin |
996 |
|
end; |
997 |
|
end; |
998 |
|
|
999 |
< |
procedure TIBDatabase.RemoveTransactions; |
999 |
> |
procedure TIBDataBase.RemoveTransactions; |
1000 |
|
var |
1001 |
|
i: Integer; |
1002 |
|
begin |
1004 |
|
RemoveTransaction(i); |
1005 |
|
end; |
1006 |
|
|
1007 |
< |
procedure TIBDatabase.SetDatabaseName(const Value: TIBFileName); |
1007 |
> |
procedure TIBDataBase.SetDatabaseName( const Value: TIBFileName); |
1008 |
|
begin |
1009 |
|
if FDBName <> Value then |
1010 |
|
begin |
1014 |
|
end; |
1015 |
|
end; |
1016 |
|
|
1017 |
< |
procedure TIBDatabase.SetDBParamByDPB(const Idx: Integer; Value: String); |
1017 |
> |
procedure TIBDataBase.SetDBParamByDPB( const Idx: Integer; Value: String); |
1018 |
|
var |
1019 |
|
ConstIdx: Integer; |
1020 |
|
begin |
1033 |
|
end; |
1034 |
|
end; |
1035 |
|
|
1036 |
< |
procedure TIBDatabase.SetDBParams(Value: TStrings); |
1036 |
> |
procedure TIBDataBase.SetDBParams(Value: TStrings); |
1037 |
|
begin |
1038 |
|
FDBParams.Assign(Value); |
1039 |
|
end; |
1040 |
|
|
1041 |
< |
procedure TIBDatabase.SetDefaultTransaction(Value: TIBTransaction); |
1041 |
> |
procedure TIBDataBase.SetDefaultTransaction(Value: TIBTransaction); |
1042 |
|
var |
1043 |
|
i: Integer; |
1044 |
|
begin |
1056 |
|
FDefaultTransaction := Value; |
1057 |
|
end; |
1058 |
|
|
1059 |
< |
procedure TIBDatabase.SetHandle(Value: TISC_DB_HANDLE); |
1059 |
> |
procedure TIBDataBase.SetHandle(Value: TISC_DB_HANDLE); |
1060 |
|
begin |
1061 |
|
if HandleIsShared then |
1062 |
|
Close |
1066 |
|
FHandleIsShared := (Value <> nil); |
1067 |
|
end; |
1068 |
|
|
1069 |
< |
procedure TIBDatabase.SetIdleTimer(Value: Integer); |
1069 |
> |
procedure TIBDataBase.SetIdleTimer(Value: Integer); |
1070 |
|
begin |
1071 |
|
if Value < 0 then |
1072 |
|
IBError(ibxeTimeoutNegative, [nil]) |
1085 |
|
end; |
1086 |
|
end; |
1087 |
|
|
1088 |
< |
function TIBDatabase.TestConnected: Boolean; |
1088 |
> |
function TIBDataBase.TestConnected: Boolean; |
1089 |
|
var |
1090 |
|
DatabaseInfo: TIBDatabaseInfo; |
1091 |
|
begin |
1106 |
|
end; |
1107 |
|
end; |
1108 |
|
|
1109 |
< |
procedure TIBDatabase.TimeoutConnection(Sender: TObject); |
1109 |
> |
procedure TIBDataBase.TimeoutConnection(Sender: TObject); |
1110 |
|
begin |
1111 |
|
if Connected then |
1112 |
|
begin |
1121 |
|
end; |
1122 |
|
end; |
1123 |
|
|
1124 |
< |
function TIBDatabase.GetIsReadOnly: Boolean; |
1124 |
> |
function TIBDataBase.GetIsReadOnly: Boolean; |
1125 |
|
var |
1126 |
|
DatabaseInfo: TIBDatabaseInfo; |
1127 |
|
begin |
1139 |
|
DatabaseInfo.Free; |
1140 |
|
end; |
1141 |
|
|
1142 |
< |
function TIBDatabase.GetSQLDialect: Integer; |
1142 |
> |
function TIBDataBase.GetSQLDialect: Integer; |
1143 |
|
begin |
1144 |
|
Result := FSQLDialect; |
1145 |
|
end; |
1146 |
|
|
1147 |
|
|
1148 |
< |
procedure TIBDatabase.SetSQLDialect(const Value: Integer); |
1148 |
> |
procedure TIBDataBase.SetSQLDialect( const Value: Integer); |
1149 |
|
begin |
1150 |
|
if (Value < 1) then IBError(ibxeSQLDialectInvalid, [nil]); |
1151 |
|
if ((FHandle = nil) or (Value <= FDBSQLDialect)) then |
1154 |
|
IBError(ibxeSQLDialectInvalid, [nil]); |
1155 |
|
end; |
1156 |
|
|
1157 |
< |
function TIBDatabase.GetDBSQLDialect: Integer; |
1157 |
> |
function TIBDataBase.GetDBSQLDialect: Integer; |
1158 |
|
var |
1159 |
|
DatabaseInfo: TIBDatabaseInfo; |
1160 |
|
begin |
1164 |
|
DatabaseInfo.Free; |
1165 |
|
end; |
1166 |
|
|
1167 |
< |
procedure TIBDatabase.ValidateClientSQLDialect; |
1167 |
> |
procedure TIBDataBase.ValidateClientSQLDialect; |
1168 |
|
begin |
1169 |
|
if (FDBSQLDialect < FSQLDialect) then |
1170 |
|
begin |
1174 |
|
end; |
1175 |
|
end; |
1176 |
|
|
1177 |
< |
procedure TIBDatabase.ApplyUpdates(const DataSets: array of TDataSet); |
1177 |
> |
procedure TIBDataBase.ApplyUpdates( const DataSets: array of TDataSet); |
1178 |
|
var |
1179 |
|
I: Integer; |
1180 |
|
DS: TIBCustomDataSet; |
1200 |
|
TR.CommitRetaining; |
1201 |
|
end; |
1202 |
|
|
1203 |
< |
procedure TIBDatabase.CloseDataSets; |
1203 |
> |
procedure TIBDataBase.CloseDataSets; |
1204 |
|
var |
1205 |
|
i: Integer; |
1206 |
|
begin |
1209 |
|
DataSets[i].close; |
1210 |
|
end; |
1211 |
|
|
1212 |
< |
function TIBDatabase.GetDataset(Index : longint) : TDataset; |
1212 |
> |
function TIBDataBase.GetDataset(Index: longint): TDataset; |
1213 |
|
begin |
1214 |
|
if (Index >= 0) and (Index < FDataSets.Count) then |
1215 |
|
Result := TDataSet(FDataSets[Index]) |
1217 |
|
raise Exception.Create('Invalid Index to DataSets'); |
1218 |
|
end; |
1219 |
|
|
1220 |
< |
function TIBDatabase.GetDataSetCount : Longint; |
1220 |
> |
function TIBDataBase.GetDataSetCount: Longint; |
1221 |
|
begin |
1222 |
|
Result := FDataSets.Count; |
1223 |
|
end; |
1238 |
|
inherited SetConnected(Value); |
1239 |
|
end; |
1240 |
|
|
1241 |
< |
procedure TIBDatabase.GetFieldNames(const TableName: string; List: TStrings); |
1241 |
> |
procedure TIBDataBase.GetFieldNames( const TableName: string; List: TStrings); |
1242 |
|
var |
1243 |
|
Query: TIBSQL; |
1244 |
|
begin |
1279 |
|
end; |
1280 |
|
end; |
1281 |
|
|
1282 |
< |
procedure TIBDatabase.GetTableNames(List: TStrings; SystemTables: Boolean); |
1282 |
> |
procedure TIBDataBase.GetTableNames(List: TStrings; SystemTables: Boolean); |
1283 |
|
var |
1284 |
|
Query : TIBSQL; |
1285 |
|
begin |
1394 |
|
IBError(ibxeNotInTransaction, [nil]); |
1395 |
|
end; |
1396 |
|
|
1397 |
+ |
procedure TIBTransaction.DoBeforeTransactionEnd; |
1398 |
+ |
begin |
1399 |
+ |
if Assigned(FBeforeTransactionEnd) then |
1400 |
+ |
FBeforeTransactionEnd(self); |
1401 |
+ |
end; |
1402 |
+ |
|
1403 |
+ |
procedure TIBTransaction.DoAfterTransactionEnd; |
1404 |
+ |
begin |
1405 |
+ |
if Assigned(FAfterTransactionEnd) then |
1406 |
+ |
FAfterTransactionEnd(self); |
1407 |
+ |
end; |
1408 |
+ |
|
1409 |
|
procedure TIBTransaction.EnsureNotInTransaction; |
1410 |
|
begin |
1411 |
|
if csDesigning in ComponentState then |
1482 |
|
CheckInTransaction; |
1483 |
|
if FInEndTransaction then Exit; |
1484 |
|
FInEndTransaction := true; |
1485 |
+ |
FEndAction := Action; |
1486 |
|
try |
1487 |
|
case Action of |
1488 |
|
TARollback, TACommit: |
1491 |
|
(Action <> FDefaultAction) and |
1492 |
|
(not Force) then |
1493 |
|
IBError(ibxeCantEndSharedTransaction, [nil]); |
1494 |
+ |
DoBeforeTransactionEnd; |
1495 |
|
for i := 0 to FSQLObjects.Count - 1 do if FSQLObjects[i] <> nil then |
1496 |
|
SQLObjects[i].DoBeforeTransactionEnd; |
1497 |
|
if InTransaction then |
1516 |
|
IBDataBaseError; |
1517 |
|
for i := 0 to FSQLObjects.Count - 1 do if FSQLObjects[i] <> nil then |
1518 |
|
SQLObjects[i].DoAfterTransactionEnd; |
1519 |
+ |
DoAfterTransactionEnd; |
1520 |
|
end; |
1521 |
|
end; |
1522 |
|
TACommitRetaining: |
1607 |
|
end; |
1608 |
|
end; |
1609 |
|
|
1610 |
+ |
function TIBTransaction.GetEndAction: TTransactionAction; |
1611 |
+ |
begin |
1612 |
+ |
if FInEndTransaction then |
1613 |
+ |
Result := FEndAction |
1614 |
+ |
else |
1615 |
+ |
IBError(ibxeIB60feature, [nil]) |
1616 |
+ |
end; |
1617 |
+ |
|
1618 |
|
|
1619 |
|
function TIBTransaction.GetIdleTimer: Integer; |
1620 |
|
begin |
1720 |
|
for i := 0 to FSQLObjects.Count - 1 do |
1721 |
|
if (FSQLObjects[i] <> nil) and |
1722 |
|
(TIBBase(FSQLObjects[i]).Database = nil) then |
1723 |
< |
SetOrdProp(TIBBase(FSQLObjects[i]).Owner, 'Database', Integer(Value)); |
1723 |
> |
SetObjectProp(TIBBase(FSQLObjects[i]).Owner, 'Database', Value); |
1724 |
|
end; |
1725 |
|
FDefaultDatabase := Value; |
1726 |
|
end; |
2147 |
|
|
2148 |
|
|
2149 |
|
|
2150 |
< |
|
2150 |
> |
|