Ignore:
Timestamp:
Mar 9, 2012, 3:02:00 PM (13 years ago)
Author:
chronos
Message:
  • Fixed: Login profile manager can lost some values during edit.
  • Added: Base initialization of TChronisClient.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UChronisClient.pas

    r43 r44  
    77uses
    88  Classes, SysUtils, SpecializedList, SpecializedDictionary;
     9
     10const
     11  SystemVersionObject = 'SystemVersion';
    912
    1013type
     
    2629    procedure Save;
    2730    procedure Delete;
    28     procedure Add;
    2931    constructor Create;
    3032    destructor Destroy; override;
     
    8183  protected
    8284    procedure InitSystemTypes; virtual;
     85    procedure Init; virtual;
    8386    function GetConnected: Boolean; virtual;
    8487  public
     
    8992    Password: string;
    9093    Types: TChronisTypeList;
     94    Version: string;
    9195    procedure ObjectLoad(AObject: TObjectProxy); virtual; abstract;
    9296    procedure ObjectSave(AObject: TObjectProxy); virtual; abstract;
    93     procedure ObjectAdd(AObject: TObjectProxy); virtual; abstract;
    9497    procedure ObjectDelete(AObject: TObjectProxy); virtual; abstract;
    9598    procedure ListLoad(AList: TListProxy); virtual; abstract;
     
    98101    procedure TypeUndefine(AType: TChronisType); virtual; abstract;
    99102    procedure CheckTypes;
     103    function TypeExists(Name: string): Boolean; virtual; abstract;
    100104    constructor Create; virtual;
    101105    destructor Destroy; override;
    102     procedure Connect; virtual; abstract;
    103     procedure Disconnect; virtual; abstract;
     106    procedure Connect; virtual;
     107    procedure Disconnect; virtual;
     108    procedure Install; virtual;
     109    procedure Uninstall; virtual;
     110    procedure Update; virtual;
    104111    property Connected: Boolean read GetConnected;
    105112  end;
     
    110117resourcestring
    111118  SClientNotSet = 'Client not set';
     119  SNotSupported = 'Not supported';
     120  SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.';
     121
    112122
    113123{ TChronisTypeList }
     
    174184end;
    175185
    176 procedure TObjectProxy.Add;
    177 begin
    178   if Assigned(Client) then Client.ObjectAdd(Self)
    179     else raise EClientNotSet.Create(SClientNotSet);
    180 end;
    181 
    182186constructor TObjectProxy.Create;
    183187begin
     
    230234procedure TChronisClient.InitSystemTypes;
    231235begin
     236end;
     237
     238procedure TChronisClient.Init;
     239var
     240  NewProxy: TListProxy;
     241  NewType: TChronisType;
     242  NewObject: TObjectProxy;
     243  DbVersion: string;
     244begin
     245  NewProxy := TListProxy.Create;
     246  NewProxy.Client := Self;
     247  NewProxy.SchemaName := 'information_schema';
     248  NewProxy.ObjectName := 'TABLES';
     249  NewProxy.Condition := '(TABLE_SCHEMA = "' + Schema +
     250    '") AND (TABLE_NAME = "' + SystemVersionObject + '")';
     251  NewProxy.Load;
     252  if NewProxy.Objects.Count > 0 then begin
     253    DbVersion := TObjectProxy(NewProxy.Objects[0]).Properties.Values['Version'];
     254    if Version <> DbVersion then
     255      raise Exception.Create(Format(SVersionMismatch, [Version, DbVersion]));
     256  end else begin
     257    NewType := TChronisType.Create;
     258    NewType.Client := Self;
     259    NewType.Name := SystemVersionObject;
     260    NewType.Properties.Add('Version', 'String');
     261    NewType.Properties.Add('Time', 'DateTime');
     262    NewType.Define;
     263
     264    NewObject := TObjectProxy.Create;
     265    NewObject.Client := Self;
     266    NewObject.SchemaName := Schema;
     267    NewObject.ObjectName := SystemVersionObject;
     268    NewObject.Properties.Add('Version', Version);
     269    NewObject.Properties.Add('Time', 'NOW()');
     270    NewObject.Save;
     271
     272    Install;
     273  end;
    232274end;
    233275
     
    287329end;
    288330
     331procedure TChronisClient.Connect;
     332begin
     333  raise Exception.Create(SNotSupported);
     334end;
     335
     336procedure TChronisClient.Disconnect;
     337begin
     338  raise Exception.Create(SNotSupported);
     339end;
     340
     341procedure TChronisClient.Install;
     342begin
     343
     344end;
     345
     346procedure TChronisClient.Uninstall;
     347begin
     348
     349end;
     350
     351procedure TChronisClient.Update;
     352begin
     353
     354end;
     355
    289356end.
    290357
Note: See TracChangeset for help on using the changeset viewer.