ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBDatabase.pas
(Generate patch)

Comparing ibx/trunk/runtime/IBDatabase.pas (file contents):
Revision 17 by tony, Sat Dec 28 19:22:24 2013 UTC vs.
Revision 21 by tony, Thu Feb 26 10:33:34 2015 UTC

# Line 279 | Line 279 | type
279  
280    TIBTransaction = class(TComponent)
281    private
282 +    FAfterTransactionEnd: TNotifyEvent;
283 +    FBeforeTransactionEnd: TNotifyEvent;
284      FIBLoaded: Boolean;
285      FCanTimeout         : Boolean;
286      FDatabases          : TList;
# Line 295 | Line 297 | type
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;
# Line 336 | Line 341 | type
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;
# Line 357 | Line 363 | type
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 }
# Line 426 | Line 436 | uses IBIntf, IBSQLMonitor, IBCustomDataS
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}
# Line 472 | Line 482 | begin
482    CheckStreamConnect;
483   end;
484  
485 < destructor TIBDatabase.Destroy;
485 > destructor TIBDataBase.Destroy;
486   var
487    i: Integer;
488   begin
# Line 498 | Line 508 | 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;
# Line 507 | Line 517 | begin
517      IBDataBaseError;
518   end;
519  
520 < procedure TIBDatabase.CheckActive;
520 > procedure TIBDataBase.CheckActive;
521   begin
522    if StreamedConnected and (not Connected) then
523      Loaded;
# Line 515 | Line 525 | begin
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
# Line 524 | Line 534 | 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
# Line 549 | Line 559 | begin
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
# Line 566 | Line 576 | begin
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
# Line 586 | Line 596 | 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
# Line 616 | Line 626 | begin
626      end;
627   end;
628  
629 < function TIBDatabase.FindDefaultTransaction(): TIBTransaction;
629 > function TIBDataBase.FindDefaultTransaction: TIBTransaction;
630   var
631    i: Integer;
632   begin
# Line 634 | Line 644 | 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
# Line 659 | Line 669 | 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
# Line 682 | Line 692 | 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
# Line 702 | Line 712 | 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
# Line 718 | Line 728 | 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
# Line 797 | Line 807 | 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
# Line 812 | Line 822 | 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;
# Line 891 | Line 901 | begin
901    end;
902   end;
903  
904 < procedure TIBDatabase.DoConnect;
904 > procedure TIBDataBase.DoConnect;
905   var
906    DPB: String;
907    TempDBParams: TStrings;
# Line 946 | Line 956 | begin
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
# Line 960 | Line 970 | begin
970    end;
971   end;
972  
973 < procedure TIBDatabase.RemoveSQLObjects;
973 > procedure TIBDataBase.RemoveSQLObjects;
974   var
975    i: Integer;
976   begin
# Line 972 | Line 982 | 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
# Line 986 | Line 996 | begin
996    end;
997   end;
998  
999 < procedure TIBDatabase.RemoveTransactions;
999 > procedure TIBDataBase.RemoveTransactions;
1000   var
1001    i: Integer;
1002   begin
# Line 994 | Line 1004 | 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
# Line 1004 | Line 1014 | 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
# Line 1023 | Line 1033 | 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
# Line 1046 | Line 1056 | 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
# Line 1056 | Line 1066 | begin
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])
# Line 1075 | Line 1085 | begin
1085        end;
1086   end;
1087  
1088 < function TIBDatabase.TestConnected: Boolean;
1088 > function TIBDataBase.TestConnected: Boolean;
1089   var
1090    DatabaseInfo: TIBDatabaseInfo;
1091   begin
# Line 1096 | Line 1106 | 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
# Line 1111 | Line 1121 | begin
1121    end;
1122   end;
1123  
1124 < function TIBDatabase.GetIsReadOnly: Boolean;
1124 > function TIBDataBase.GetIsReadOnly: Boolean;
1125   var
1126    DatabaseInfo: TIBDatabaseInfo;
1127   begin
# Line 1129 | Line 1139 | 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
# Line 1144 | Line 1154 | begin
1154      IBError(ibxeSQLDialectInvalid, [nil]);
1155   end;
1156  
1157 < function TIBDatabase.GetDBSQLDialect: Integer;
1157 > function TIBDataBase.GetDBSQLDialect: Integer;
1158   var
1159    DatabaseInfo: TIBDatabaseInfo;
1160   begin
# Line 1154 | Line 1164 | begin
1164    DatabaseInfo.Free;
1165   end;
1166  
1167 < procedure TIBDatabase.ValidateClientSQLDialect;
1167 > procedure TIBDataBase.ValidateClientSQLDialect;
1168   begin
1169    if (FDBSQLDialect < FSQLDialect) then
1170    begin
# Line 1164 | Line 1174 | 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;
# Line 1190 | Line 1200 | begin
1200    TR.CommitRetaining;
1201   end;
1202  
1203 < procedure TIBDatabase.CloseDataSets;
1203 > procedure TIBDataBase.CloseDataSets;
1204   var
1205    i: Integer;
1206   begin
# Line 1199 | Line 1209 | 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])
# Line 1207 | Line 1217 | begin
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;
# Line 1228 | Line 1238 | begin
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
# Line 1269 | Line 1279 | 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
# Line 1384 | Line 1394 | 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
# Line 1460 | Line 1482 | begin
1482    CheckInTransaction;
1483    if FInEndTransaction then Exit;
1484    FInEndTransaction := true;
1485 +  FEndAction := Action;
1486    try
1487    case Action of
1488      TARollback, TACommit:
# Line 1468 | Line 1491 | begin
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
# Line 1492 | Line 1516 | begin
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:
# Line 1582 | Line 1607 | begin
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
# Line 1687 | Line 1720 | 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;
# Line 2114 | Line 2147 | end.
2147  
2148  
2149  
2150 <
2150 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines