Changeset 37 for trunk/Application


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.
Location:
trunk/Application
Files:
3 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
  • trunk/Application/UChronisClient.pas

    r34 r37  
    1919    Properties: TDictionaryStringString;
    2020    Client: TChronisClient;
     21    ObjectName: string;
     22    SchemaName: string;
    2123    procedure Load;
    2224    procedure Save;
     
    3941    ColumnsFilter: TListString;
    4042    ColummsFilterUse: Boolean;
    41     ConditionColumn: string;
    42     ConditionValue: string;
    43     ConditionUse: Boolean;
     43    Condition: string;
    4444    ObjectName: string;
    4545    SchemaName: string;
    4646    Objects: TListObject; // TListObject<TObjectProxy>
    47     procedure SetCondition(ColumnName: string; Value: string);
    4847    procedure Clear;
    4948    constructor Create;
     
    5352  end;
    5453
     54  TChronisType = class
     55    OID: Integer;
     56    Name: string;
     57  end;
     58
     59  TChronisTypeRecordItem = class
     60    Name: string;
     61    ItemType: TChronisType;
     62  end;
     63
     64  { TChronisTypeRecord }
     65
     66  TChronisTypeRecord = class(TChronisType)
     67    Items: TListObject; // TListObject<TChronisTypeRecordItem>
     68    constructor Create;
     69    destructor Destroy; override;
     70  end;
     71
    5572  { TChronisClient }
    5673
    5774  TChronisClient = class
     75  protected
     76    function GetConnected: Boolean; virtual;
     77  public
    5878    Host: string;
    5979    Port: Word;
     
    6787    procedure ListLoad(AList: TListProxy); virtual; abstract;
    6888    procedure ListSave(AList: TListProxy); virtual; abstract;
     89    procedure DefineType(AType: TChronisType); virtual; abstract;
     90    procedure UndefineType(AType: TChronisType); virtual; abstract;
    6991    constructor Create; virtual;
     92    procedure Connect; virtual; abstract;
     93    procedure Disconnect; virtual; abstract;
     94    property Connected: Boolean read GetConnected;
    7095  end;
    7196
    7297implementation
     98
     99{ TChronisTypeRecord }
     100
     101constructor TChronisTypeRecord.Create;
     102begin
     103  Items := TListObject.Create;
     104end;
     105
     106destructor TChronisTypeRecord.Destroy;
     107begin
     108  Items.Free;
     109  inherited Destroy;
     110end;
    73111
    74112{ TObjectProxy }
     
    107145{ TListProxy }
    108146
    109 procedure TListProxy.SetCondition(ColumnName: string; Value: string);
    110 begin
    111   ConditionColumn := ColumnName;
    112   ConditionValue := Value;
    113   ConditionUse := True;
    114 end;
    115 
    116147procedure TListProxy.Clear;
    117148begin
    118   ConditionUse := False;
    119149  PageUse := False;
    120150  ColummsFilterUse := False;
     
    148178{ TChronisClient }
    149179
     180function TChronisClient.GetConnected: Boolean;
     181begin
     182  Result := False;
     183end;
     184
    150185constructor TChronisClient.Create;
    151186begin
  • trunk/Application/UDataTypes.pas

    r23 r37  
    66
    77uses
    8   Classes, SysUtils, Controls, Spin, StdCtrls, ExtCtrls, MaskEdit, EditBtn;
     8  Classes, SysUtils, Controls, Spin, StdCtrls, ExtCtrls, MaskEdit, EditBtn,
     9  UChronisClient;
    910
    1011type
     
    147148function GetDataType(ACustomType: Integer): TDataType;
    148149var
    149   DbRows: TDbRows;
     150  Proxy: TListProxy;
    150151  BaseType: Integer;
    151152begin
    152153  try
    153     DbRows := TDbRows.Create;
    154     Core.System.Database.Select(DbRows, CustomTypeTableName, '*', 'Id=' + IntToStr(ACustomType));
    155     BaseType := StrToInt(DbRows[0].Values['Type']);
     154    Proxy := TListProxy.Create;
     155    Proxy.Client := Core.System.Client;
     156    Proxy.ObjectName := CustomTypeTableName;
     157    Proxy.Condition := 'Id=' + IntToStr(ACustomType);
     158    Proxy.Load;
     159    BaseType := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['Type']);
    156160  finally
    157     DbRows.Free;
     161    Proxy.Free;
    158162  end;
    159163
     
    231235procedure TDataTypeRelationMany.LoadDef(ACustomType: Integer);
    232236var
    233   DbRows: TDbRows;
     237  Proxy: TListProxy;
    234238  BaseType: Integer;
    235239begin
    236240  try
    237     DbRows := TDbRows.Create;
    238     Core.System.Database.Select(DbRows, TypeRelationMany, '*', 'CustomType=' + IntToStr(ACustomType));
    239     PropertyID := StrToInt(DbRows[0].Values['ObjectProperty']);
     241    Proxy := TListProxy.Create;
     242    Proxy.Client := Core.System.Client;
     243    Proxy.ObjectName := TypeRelationMany;
     244    Proxy.Condition := 'CustomType=' + IntToStr(ACustomType);
     245    Proxy.Load;
     246    PropertyID := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['ObjectProperty']);
    240247  finally
    241     DbRows.Free;
     248    Proxy.Free;
    242249  end;
    243250  try
    244     DbRows := TDbRows.Create;
    245     Core.System.Database.Select(DbRows, PropertyTable, '*', 'Id=' + IntToStr(PropertyID));
    246     ObjectId := StrToInt(DbRows[0].Values['Object']);
    247     PropertyName := DbRows[0].Values['ColumnName'];
     251    Proxy := TListProxy.Create;
     252    Proxy.Client := Core.System.Client;
     253    Proxy.ObjectName := PropertyTable;
     254    Proxy.Condition := 'Id=' + IntToStr(PropertyID);
     255    ObjectId := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['Object']);
     256    PropertyName := TObjectProxy(Proxy.Objects[0]).Properties.Values['ColumnName'];
    248257  finally
    249     DbRows.Free;
     258    Proxy.Free;
    250259  end;
    251260end;
     
    286295procedure TDataTypeRelationOne.LoadDef(ACustomType: Integer);
    287296var
    288   DbRows: TDbRows;
     297  Proxy: TListProxy;
    289298begin
    290299  try
    291     DbRows := TDbRows.Create;
    292     Core.System.Database.Select(DbRows, TypeRelationOne, '*', 'CustomType=' + IntToStr(ACustomType));
    293     ObjectId := StrToInt(DbRows[0].Values['Object']);
     300    Proxy := TListProxy.Create;
     301    Proxy.Client := Core.System.Client;
     302    Proxy.ObjectName := TypeRelationOne;
     303    Proxy.Condition := 'CustomType=' + IntToStr(ACustomType);
     304    Proxy.Load;
     305    ObjectId := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['Object']);
    294306  finally
    295     DbRows.Free;
     307    Proxy.Free;
    296308  end;
    297309end;
Note: See TracChangeset for help on using the changeset viewer.