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/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
Note: See TracChangeset for help on using the changeset viewer.