Changeset 37 for trunk/Application/Clients/UChronisClientMySQL.pas
- Timestamp:
- Mar 8, 2012, 3:11:10 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Clients/UChronisClientMySQL.pas
r34 r37 13 13 14 14 TChronisClientMySQL = class(TChronisClient) 15 protected 16 function GetConnected: Boolean; override; 17 public 15 18 Database: TSqlDatabase; 16 19 procedure ObjectLoad(AObject: TObjectProxy); override; … … 20 23 procedure ListLoad(AList: TListProxy); override; 21 24 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; 23 30 destructor Destroy; override; 31 procedure Connect; override; 32 procedure Disconnect; override; 24 33 end; 25 34 … … 27 36 28 37 { TChronisClientMySQL } 38 39 function TChronisClientMySQL.GetConnected: Boolean; 40 begin 41 Result := Database.Connected; 42 end; 29 43 30 44 procedure TChronisClientMySQL.ObjectLoad(AObject: TObjectProxy); … … 52 66 DbRows: TDbRows; 53 67 Filter: string; 54 Condition: string;68 DbCondition: string; 55 69 I: Integer; 56 70 NewObject: TObjectProxy; 71 Table: string; 57 72 begin 58 73 try … … 64 79 Delete(Filter, Length(Filter) - 1, 2); 65 80 end else Filter := '*'; 66 if AList.Condition Use 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); 71 86 AList.Objects.Clear; 72 87 for I := 0 to DbRows.Count - 1 do begin … … 86 101 end; 87 102 103 procedure TChronisClientMySQL.DefineType(AType: TChronisType); 104 var 105 Data: TDictionaryStringString; 106 I: Integer; 107 begin 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; 128 end; 129 130 procedure TChronisClientMySQL.UndefineType(AType: TChronisType); 131 begin 132 133 end; 134 135 procedure TChronisClientMySQL.Install; 136 begin 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'];*) 147 end; 148 149 procedure TChronisClientMySQL.Uninstall; 150 begin 151 152 end; 153 88 154 constructor TChronisClientMySQL.Create; 89 155 begin … … 97 163 end; 98 164 165 procedure TChronisClientMySQL.Connect; 166 begin 167 Database.Port := Port; 168 Database.UserName := User; 169 Database.Password := Password; 170 Database.HostName := Host; 171 Database.Database := Schema; 172 Database.Connect; 173 end; 174 175 procedure TChronisClientMySQL.Disconnect; 176 begin 177 Database.Disconnect; 178 end; 179 99 180 end. 100 181
Note:
See TracChangeset
for help on using the changeset viewer.