Ignore:
Timestamp:
Mar 8, 2012, 3:11:10 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Direct acces using Database: TSqlDatabase replaced by TChronisClient interface.
File:
1 edited

Legend:

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

    r34 r37  
    1313
    1414  TChronisClientMySQL = class(TChronisClient)
     15  protected
     16    function GetConnected: Boolean; override;
     17  public
    1518    Database: TSqlDatabase;
    1619    procedure ObjectLoad(AObject: TObjectProxy); override;
     
    2023    procedure ListLoad(AList: TListProxy); override;
    2124    procedure ListSave(AList: TListProxy); override;
    22     constructor Create;
     25    procedure DefineType(AType: TChronisType); override;
     26    procedure UndefineType(AType: TChronisType); override;
     27    procedure Install;
     28    procedure Uninstall;
     29    constructor Create; override;
    2330    destructor Destroy; override;
     31    procedure Connect; override;
     32    procedure Disconnect; override;
    2433  end;
    2534
     
    2736
    2837{ TChronisClientMySQL }
     38
     39function TChronisClientMySQL.GetConnected: Boolean;
     40begin
     41  Result := Database.Connected;
     42end;
    2943
    3044procedure TChronisClientMySQL.ObjectLoad(AObject: TObjectProxy);
     
    5266  DbRows: TDbRows;
    5367  Filter: string;
    54   Condition: string;
     68  DbCondition: string;
    5569  I: Integer;
    5670  NewObject: TObjectProxy;
     71  Table: string;
    5772begin
    5873  try
     
    6479      Delete(Filter, Length(Filter) - 1, 2);
    6580    end else Filter := '*';
    66     if AList.ConditionUse then Condition := '`' + AList.ConditionColumn + '` = "' +
    67       AList.ConditionValue + '"'
    68       else Condition := '1';
    69     Database.Query(DbRows, 'SELECT ' + Filter + ' FROM `' + AList.SchemaName + '`.`' +
    70       AList.ObjectName + '` WHERE ' + Condition);
     81    if AList.Condition <> '' then DbCondition := ' WHERE ' + AList.Condition
     82      else DbCondition := '';
     83    Table := '`' + AList.ObjectName + '`';
     84    if AList.SchemaName <> '' then Table := '`' + AList.SchemaName + '`.' + Table;
     85    Database.Query(DbRows, 'SELECT ' + Filter + ' FROM ' + Table + DbCondition);
    7186    AList.Objects.Clear;
    7287    for I := 0 to DbRows.Count - 1 do begin
     
    86101end;
    87102
     103procedure TChronisClientMySQL.DefineType(AType: TChronisType);
     104var
     105  Data: TDictionaryStringString;
     106  I: Integer;
     107begin
     108  try
     109    Data := TDictionaryStringString.Create;
     110    Data.Add('Name', AType.Name);
     111    Database.Insert('Type', Data);
     112  finally
     113    Data.Free;
     114  end;
     115  if AType is TChronisTypeRecord then begin
     116    for I := 0 to TChronisTypeRecord(AType).Items.Count - 1 do
     117      try
     118        Data := TDictionaryStringString.Create;
     119        Data.Add('Name',
     120          TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).Name);
     121        Data.Add('Type', IntToStr(
     122          TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).ItemType.OID));
     123        Database.Insert('TypeRecordItem', Data);
     124      finally
     125        Data.Free;
     126      end;
     127  end;
     128end;
     129
     130procedure TChronisClientMySQL.UndefineType(AType: TChronisType);
     131begin
     132
     133end;
     134
     135procedure TChronisClientMySQL.Install;
     136begin
     137(*  if Tables.IndexOf(InformationTable) = -1 then begin
     138    Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + InformationTable + '` ( ' +
     139'`Version` varchar(255) NOT NULL,' +
     140'`LastUpdateTime` datetime NOT NULL' +
     141') ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     142    Database.Query(DbRows, 'INSERT INTO `' + InformationTable + '` (`Version`, `LastUpdateTime`) VALUES ' +
     143'("0.1", "0000-00-00 00:00:00");');
     144  end;
     145  Database.Select(DbRows, InformationTable);
     146  StructureVersion := DbRows[0].Values['Version'];*)
     147end;
     148
     149procedure TChronisClientMySQL.Uninstall;
     150begin
     151
     152end;
     153
    88154constructor TChronisClientMySQL.Create;
    89155begin
     
    97163end;
    98164
     165procedure TChronisClientMySQL.Connect;
     166begin
     167  Database.Port := Port;
     168  Database.UserName := User;
     169  Database.Password := Password;
     170  Database.HostName := Host;
     171  Database.Database := Schema;
     172  Database.Connect;
     173end;
     174
     175procedure TChronisClientMySQL.Disconnect;
     176begin
     177  Database.Disconnect;
     178end;
     179
    99180end.
    100181
Note: See TracChangeset for help on using the changeset viewer.