Ignore:
Timestamp:
Mar 9, 2012, 1:09:52 PM (13 years ago)
Author:
chronos
Message:
  • Fixed: Selection of available protocols in profile manager.
  • Modified: Initialization of persistent data structures rewrited to more native structures.
File:
1 edited

Legend:

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

    r40 r43  
    1414  TChronisClientMySQL = class(TChronisClient)
    1515  protected
     16    procedure InitSystemTypes; override;
    1617    function GetConnected: Boolean; override;
    1718  public
     
    2324    procedure ListLoad(AList: TListProxy); override;
    2425    procedure ListSave(AList: TListProxy); override;
    25     procedure DefineType(AType: TChronisType); override;
    26     procedure UndefineType(AType: TChronisType); override;
     26    procedure TypeDefine(AType: TChronisType); override;
     27    procedure TypeUndefine(AType: TChronisType); override;
    2728    procedure Install;
    2829    procedure Uninstall;
     
    3536implementation
    3637
     38
     39resourcestring
     40  SMissingBaseType = 'Missing base typ for %s';
     41  SUndefinedType = 'Undefinned type %s';
     42
     43
    3744{ TChronisClientMySQL }
     45
     46procedure TChronisClientMySQL.InitSystemTypes;
     47begin
     48  inherited InitSystemTypes;
     49  Types.AddType('Integer', 'int(11)');
     50  Types.AddType('String', 'varchar(255)');
     51  Types.AddType('RelationOne', 'int(11)');
     52  Types.AddType('Double', 'double');
     53  Types.AddType('DateTime', 'datetime');
     54  Types.AddType('Date', 'date');
     55  Types.AddType('Time', 'time');
     56  Types.AddType('Text', 'text');
     57  Types.AddType('Boolean', 'bool');
     58end;
    3859
    3960function TChronisClientMySQL.GetConnected: Boolean;
     
    103124end;
    104125
    105 procedure TChronisClientMySQL.DefineType(AType: TChronisType);
     126procedure TChronisClientMySQL.TypeDefine(AType: TChronisType);
    106127var
    107   Data: TDictionaryStringString;
     128  DbRows: TDbRows;
    108129  I: Integer;
     130  Query: string;
     131  RefType: TChronisType;
    109132begin
    110133  try
    111     Data := TDictionaryStringString.Create;
    112     Data.Add('Name', AType.Name);
    113     Database.Insert('Type', Data);
     134    DbRows := TDbRows.Create;
     135    Query := 'CREATE TABLE IF NOT EXISTS `' + AType.Name + '` ( ' +
     136      '`Id` int(11) NOT NULL AUTO_INCREMENT,';
     137    for I := 0 to AType.Properties.Count - 1 do
     138    with AType.Properties do begin
     139      RefType := Types.SearchByName(Items[I].Value);
     140      if not Assigned(RefType) then
     141        raise Exception.Create(Format(SUndefinedType, [Items[I].Value]));
     142      if RefType.DbType = '' then
     143        raise Exception.Create(Format(SMissingBaseType, [RefType.Name]));
     144
     145      Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' NOT NULL,';
     146    end;
     147    Query := Query + 'PRIMARY KEY (`Id`)' +
     148      ') ENGINE=InnoDB  DEFAULT CHARSET=utf8';
     149    Database.Query(DbRows, Query);
    114150  finally
    115     Data.Free;
    116   end;
    117   if AType is TChronisTypeRecord then begin
    118     for I := 0 to TChronisTypeRecord(AType).Items.Count - 1 do
    119       try
    120         Data := TDictionaryStringString.Create;
    121         Data.Add('Name',
    122           TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).Name);
    123         Data.Add('Type', IntToStr(
    124           TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).ItemType.OID));
    125         Database.Insert('TypeRecordItem', Data);
    126       finally
    127         Data.Free;
    128       end;
    129   end;
    130 end;
    131 
    132 procedure TChronisClientMySQL.UndefineType(AType: TChronisType);
     151    DbRows.Free;
     152  end;
     153end;
     154
     155procedure TChronisClientMySQL.TypeUndefine(AType: TChronisType);
    133156begin
    134157
     
    156179constructor TChronisClientMySQL.Create;
    157180begin
     181  inherited;
    158182  Database := TSqlDatabase.Create(nil);
    159183end;
Note: See TracChangeset for help on using the changeset viewer.