Changeset 44 for trunk/Application/Clients/UChronisClientMySQL.pas
- Timestamp:
- Mar 9, 2012, 3:02:00 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Clients/UChronisClientMySQL.pas
r43 r44 16 16 procedure InitSystemTypes; override; 17 17 function GetConnected: Boolean; override; 18 procedure Init; override; 18 19 public 19 20 Database: TSqlDatabase; 20 21 procedure ObjectLoad(AObject: TObjectProxy); override; 21 22 procedure ObjectSave(AObject: TObjectProxy); override; 22 procedure ObjectAdd(AObject: TObjectProxy); override;23 23 procedure ObjectDelete(AObject: TObjectProxy); override; 24 24 procedure ListLoad(AList: TListProxy); override; … … 64 64 65 65 procedure TChronisClientMySQL.ObjectLoad(AObject: TObjectProxy); 66 begin 67 66 var 67 DbRows: TDbRows; 68 NewObject: TObjectProxy; 69 Table: string; 70 begin 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; 68 81 end; 69 82 70 83 procedure 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); 84 var 85 DbRows: TDbRows; 86 NewObject: TObjectProxy; 87 Table: string; 88 begin 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; 78 96 end; 79 97 80 98 procedure TChronisClientMySQL.ObjectDelete(AObject: TObjectProxy); 81 99 begin 82 inherited ObjectDelete(AObject); 100 Database.Delete(AObject.ObjectName, 'Id=' + IntToStr(AObject.Id), 101 AObject.SchemaName); 83 102 end; 84 103 … … 143 162 raise Exception.Create(Format(SMissingBaseType, [RefType.Name])); 144 163 145 Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' N OT NULL,';164 Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' NULL,'; 146 165 end; 147 166 Query := Query + 'PRIMARY KEY (`Id`)' + … … 177 196 end; 178 197 198 procedure TChronisClientMySQL.Init; 199 begin 200 inherited; 201 end; 202 179 203 constructor TChronisClientMySQL.Create; 180 204 begin … … 197 221 Database.Database := Schema; 198 222 Database.Connect; 223 Init; 199 224 end; 200 225
Note:
See TracChangeset
for help on using the changeset viewer.