Changeset 44


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

Legend:

Unmodified
Added
Removed
  • trunk/Application/Clients/UChronisClientMySQL.pas

    r43 r44  
    1616    procedure InitSystemTypes; override;
    1717    function GetConnected: Boolean; override;
     18    procedure Init; override;
    1819  public
    1920    Database: TSqlDatabase;
    2021    procedure ObjectLoad(AObject: TObjectProxy); override;
    2122    procedure ObjectSave(AObject: TObjectProxy); override;
    22     procedure ObjectAdd(AObject: TObjectProxy); override;
    2323    procedure ObjectDelete(AObject: TObjectProxy); override;
    2424    procedure ListLoad(AList: TListProxy); override;
     
    6464
    6565procedure TChronisClientMySQL.ObjectLoad(AObject: TObjectProxy);
    66 begin
    67 
     66var
     67  DbRows: TDbRows;
     68  NewObject: TObjectProxy;
     69  Table: string;
     70begin
     71  try
     72    DbRows := TDbRows.Create;
     73    Table := '`' + AObject.ObjectName + '`';
     74    if AObject.SchemaName <> '' then Table := '`' + AObject.SchemaName + '`.' + Table;
     75    Database.Query(DbRows, 'SELECT * FROM ' + Table +
     76      ' WHERE `Id`=' + IntToStr(AObject.Id));
     77    AObject.Properties.Assign(TDictionaryStringString(DbRows[0]));
     78  finally
     79    DbRows.Free;
     80  end;
    6881end;
    6982
    7083procedure TChronisClientMySQL.ObjectSave(AObject: TObjectProxy);
    71 begin
    72   inherited ObjectSave(AObject);
    73 end;
    74 
    75 procedure TChronisClientMySQL.ObjectAdd(AObject: TObjectProxy);
    76 begin
    77   inherited ObjectAdd(AObject);
     84var
     85  DbRows: TDbRows;
     86  NewObject: TObjectProxy;
     87  Table: string;
     88begin
     89  try
     90    DbRows := TDbRows.Create;
     91    Database.Replace(AObject.ObjectName, AObject.Properties, AObject.SchemaName);
     92    if AObject.Id = 0 then AObject.Id := Database.LastInsertId;
     93  finally
     94    DbRows.Free;
     95  end;
    7896end;
    7997
    8098procedure TChronisClientMySQL.ObjectDelete(AObject: TObjectProxy);
    8199begin
    82   inherited ObjectDelete(AObject);
     100  Database.Delete(AObject.ObjectName, 'Id=' + IntToStr(AObject.Id),
     101    AObject.SchemaName);
    83102end;
    84103
     
    143162        raise Exception.Create(Format(SMissingBaseType, [RefType.Name]));
    144163
    145       Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' NOT NULL,';
     164      Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' NULL,';
    146165    end;
    147166    Query := Query + 'PRIMARY KEY (`Id`)' +
     
    177196end;
    178197
     198procedure TChronisClientMySQL.Init;
     199begin
     200  inherited;
     201end;
     202
    179203constructor TChronisClientMySQL.Create;
    180204begin
     
    197221  Database.Database := Schema;
    198222  Database.Connect;
     223  Init;
    199224end;
    200225
  • trunk/Application/Clients/UChronisClientXMLRPC.pas

    r43 r44  
    99
    1010type
     11
     12  { TChronisClientXMLRPC }
     13
    1114  TChronisClientXMLRPC = class(TChronisClient)
    1215  end;
     
    1417implementation
    1518
     19
    1620end.
    1721
  • 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
  • trunk/Forms/UFormLoginProfile.pas

    r43 r44  
    6868    procedure SpinEditPortChange(Sender: TObject);
    6969  private
     70    SelectedProfile: TConnectProfile;
    7071    ProfileList: TProfileList;
    7172  public
    72 
    7373  end;
    7474
     
    128128procedure TLoginProfileForm.ComboBoxProtocolChange(Sender: TObject);
    129129begin
    130   if ListBoxProfiles.ItemIndex <> - 1 then
    131     TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Protocol :=
     130  if Assigned(SelectedProfile) then
     131    SelectedProfile.Protocol :=
    132132      TConnectProtocol(ComboBoxProtocol.Items.Objects[ComboBoxProtocol.ItemIndex]);
    133133end;
     
    135135procedure TLoginProfileForm.EditNameChange(Sender: TObject);
    136136begin
    137   if ListBoxProfiles.ItemIndex <> - 1 then begin
    138     TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Name := EditName.Text;
     137  if Assigned(SelectedProfile) then begin
     138    SelectedProfile.Name := EditName.Text;
    139139    ListBoxProfiles.Items[ListBoxProfiles.ItemIndex] := EditName.Text;
    140140  end;
     
    143143procedure TLoginProfileForm.EditDatabaseChange(Sender: TObject);
    144144begin
    145   if ListBoxProfiles.ItemIndex <> - 1 then
    146     TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Database := EditDatabase.Text;
     145  if Assigned(SelectedProfile) then
     146    SelectedProfile.Database := EditDatabase.Text;
    147147end;
    148148
    149149procedure TLoginProfileForm.EditServerChange(Sender: TObject);
    150150begin
    151   if ListBoxProfiles.ItemIndex <> - 1 then
    152     TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).HostName := EditServer.Text;
     151  if Assigned(SelectedProfile) then
     152    SelectedProfile.HostName := EditServer.Text;
    153153end;
    154154
     
    202202  if ListBoxProfiles.ItemIndex <> -1 then
    203203  with TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]) do begin
     204    SelectedProfile := nil;
    204205    EditServer.Text := HostName;
    205206    EditDatabase.Text := Database;
     
    207208    SpinEditPort.Value := Port;
    208209    EditName.Text := Name;
     210    SelectedProfile := TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]);
    209211  end;
    210212end;
     
    212214procedure TLoginProfileForm.SpinEditPortChange(Sender: TObject);
    213215begin
    214   if ListBoxProfiles.ItemIndex <> - 1 then
    215     TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Port := SpinEditPort.Value;
     216  if Assigned(SelectedProfile) then
     217    SelectedProfile.Port := SpinEditPort.Value;
    216218end;
    217219
  • trunk/Forms/UFormMain.pas

    r43 r44  
    307307    Core.System.Types.Clear;
    308308    FreeAndNil(Core.Client);
    309     UpdateInterface;
    310   end;
     309    Core.System.Client := Core.Client;
     310  end;
     311  UpdateInterface;
    311312end;
    312313
  • trunk/Languages/chronis.cs.po

    r43 r44  
    415415msgstr "Nenastaven klient"
    416416
     417#: uchronisclient.snotsupported
     418msgid "Not supported"
     419msgstr ""
     420
     421#: uchronisclient.sversionmismatch
     422msgid "Version mismatch, client: %0:s, server: %1:s. Please upgrade database."
     423msgstr ""
     424
    417425#: uchronisclientmysql.smissingbasetype
    418426msgid "Missing base typ for %s"
  • trunk/Languages/chronis.po

    r43 r44  
    393393msgstr ""
    394394
     395#: uchronisclient.snotsupported
     396msgid "Not supported"
     397msgstr ""
     398
     399#: uchronisclient.sversionmismatch
     400msgid "Version mismatch, client: %0:s, server: %1:s. Please upgrade database."
     401msgstr ""
     402
    395403#: uchronisclientmysql.smissingbasetype
    396404msgid "Missing base typ for %s"
  • trunk/USystem.pas

    r43 r44  
    316316    Proxy.Client := Client;
    317317    Proxy.ObjectName := ObjectTable;
    318     Proxy.Properties.Add('Name', Name);
    319     Proxy.Properties.Add('Schema', Schema);
    320     Proxy.Properties.Add('Table', TableName);
    321     Proxy.Properties.Add('Group', IntToStr(GroupId));
     318    with Proxy.Properties do begin
     319      Add('Name', Name);
     320      Add('Schema', Schema);
     321      Add('Table', TableName);
     322      Add('Group', IntToStr(GroupId));
     323      Add('PrimaryKey', 'Id');
     324    end;
    322325    Proxy.Save;
    323326    Result := Proxy.Id;
     
    360363    Proxy.ObjectName := CustomTypeTableName;
    361364    Proxy.Properties.Add('Type', IntToStr(Integer(vtInteger)));
     365    Proxy.Save;
    362366    CustomTypeId := Proxy.Id;
    363367
     368    Proxy.Id := 0;
    364369    Proxy.ObjectName := TypeNumber;
    365370    Proxy.Properties.Clear;
     
    389394    Proxy.ObjectName := CustomTypeTableName;
    390395    Proxy.Properties.Add('Type', IntToStr(Integer(vtFloat)));
     396    Proxy.Save;
    391397    CustomTypeId := Proxy.Id;
    392398
     399    Proxy.Id := 0;
    393400    Proxy.ObjectName := TypeFloat;
    394401    Proxy.Properties.Clear;
     
    421428    CustomTypeId := Proxy.Id;
    422429
     430    Proxy.Id := 0;
    423431    Proxy.ObjectName := TypeDateTime;
    424432    Proxy.Properties.Clear;
     
    450458    CustomTypeId := Proxy.Id;
    451459
     460    Proxy.Id := 0;
    452461    Proxy.ObjectName := TypeString;
    453462    Proxy.Properties.Clear;
     
    478487    CustomTypeId := Proxy.Id;
    479488
     489    Proxy.Id := 0;
    480490    Proxy.ObjectName := TypeString;
    481491    Proxy.Properties.Clear;
     
    505515    CustomTypeId := Proxy.Id;
    506516
     517    Proxy.Id := 0;
    507518    Proxy.ObjectName := TypeRelationOne;
    508519    Proxy.Properties.Clear;
     
    528539    Proxy.Client := Client;
    529540    Proxy.ObjectName := CustomTypeTableName;
    530 
    531541    Proxy.Properties.Clear;
    532542    Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationMany)));
     
    534544    CustomTypeId := Proxy.Id;
    535545
     546    Proxy.Id := 0;
    536547    Proxy.ObjectName := TypeRelationMany;
    537548    Proxy.Properties.Clear;
     
    590601    Proxy.Properties.Add('Enumeration', IntToStr(Enum));
    591602    Proxy.Properties.Add('Name', Name);
     603    Proxy.Properties.Add('Sequence', '0');
    592604    Proxy.Save;
    593605    Result := Proxy.Id;
  • trunk/chronis.lpi

    r43 r44  
    105105      </Item6>
    106106    </RequiredPackages>
    107     <Units Count="26">
     107    <Units Count="27">
    108108      <Unit0>
    109109        <Filename Value="chronis.lpr"/>
     
    263263        <UnitName Value="URemote"/>
    264264      </Unit25>
     265      <Unit26>
     266        <Filename Value="Module/UModuleUser.pas"/>
     267        <IsPartOfProject Value="True"/>
     268        <UnitName Value="UModuleUser"/>
     269      </Unit26>
    265270    </Units>
    266271  </ProjectOptions>
  • trunk/chronis.lpr

    r42 r44  
    1515  UModuleSystem,
    1616UFormItemList, LDockTree, UChronisClientXMLRPC, UChronisClientMySQL,
    17   URemote
     17  URemote, UModuleUser
    1818  { you can add units after this };
    1919
Note: See TracChangeset for help on using the changeset viewer.