Changeset 11 for trunk/USystem.pas
- Timestamp:
- Jun 9, 2011, 12:34:21 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/USystem.pas
r9 r11 6 6 7 7 uses 8 Classes, SysUtils, SpecializedList, USqlDatabase, Strings; 8 Classes, SysUtils, SpecializedList, SpecializedDictionary, USqlDatabase, 9 Strings; 10 11 const 12 ObjectGroupTable = 'ObjectGroup'; 13 ObjectTable = 'Object'; 14 InformationTable = 'Information'; 15 PropertyTable = 'Property'; 16 PropertyTypeTable = 'Type'; 17 PropertyGroupTable = 'PropertyGroup'; 9 18 10 19 type 11 20 TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean, 12 21 vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword, 13 vtReference, vtDate, vtTime, vtColor );22 vtReference, vtDate, vtTime, vtColor, vtCurrency); 14 23 15 24 TChronisType = class; … … 63 72 DbType: string; 64 73 DbTable: string; 74 TypeIndex: Integer; 65 75 Parent: TChronisType; 66 76 end; … … 71 81 Types: TListObject; // TList<TChronisType> 72 82 Database: TSQLDatabase; 83 function AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer; 84 function AddObject(Name, TableName, Schema: string; GroupId: Integer): Integer; 85 function AddProperty(ObjectId: Integer; Name, ColumnName: string; DataType: Integer): Integer; 86 function AddObjectGroup(Name: string): Integer; 73 87 constructor Create; 74 88 destructor Destroy; override; … … 107 121 try 108 122 Properties := TDbRows.Create; 109 Base.Database.Query(Properties, 'SELECT * FROM ` Property` WHERE `Object`='110 + IntToStr(Obj.Id));123 Base.Database.Query(Properties, 'SELECT * FROM `' + PropertyTable + 124 '` WHERE `Object`=' + IntToStr(Obj.Id)); 111 125 Columns.Clear; 112 126 NewColumn := TReportColumn.Create; … … 149 163 end; 150 164 165 function TChronisBase.AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer; 166 var 167 DbRows: TDbRows; 168 Data: TDictionaryStringString; 169 begin 170 try 171 DbRows := TDbRows.Create; 172 Data := TDictionaryStringString.Create; 173 Data.Add('Name', Name); 174 Data.Add('DbType', DataType); 175 Data.Add('TypeIndex', IntToStr(Integer(TypeIndex))); 176 Database.Insert(PropertyTypeTable, Data); 177 Result := Database.LastInsertId; 178 finally 179 Data.Free; 180 DbRows.Free; 181 end; 182 end; 183 184 function TChronisBase.AddObject(Name, TableName, Schema: string; 185 GroupId: Integer): Integer; 186 var 187 DbRows: TDbRows; 188 Data: TDictionaryStringString; 189 begin 190 try 191 DbRows := TDbRows.Create; 192 Data := TDictionaryStringString.Create; 193 Data.Add('Name', Name); 194 Data.Add('Schema', Schema); 195 Data.Add('Table', TableName); 196 Data.Add('Group', IntToStr(GroupId)); 197 Database.Insert(ObjectTable, Data); 198 Result := Database.LastInsertId; 199 finally 200 Data.Free; 201 DbRows.Free; 202 end; 203 end; 204 205 function TChronisBase.AddProperty(ObjectId: Integer; Name, ColumnName: string; 206 DataType: Integer): Integer; 207 var 208 DbRows: TDbRows; 209 Data: TDictionaryStringString; 210 begin 211 try 212 DbRows := TDbRows.Create; 213 Data := TDictionaryStringString.Create; 214 Data.Add('Name', Name); 215 Data.Add('Object', IntToStr(ObjectId)); 216 Data.Add('ColumnName', ColumnName); 217 Data.Add('Type', IntToStr(DataType)); 218 Database.Insert(PropertyTable, Data); 219 Result := Database.LastInsertId; 220 finally 221 Data.Free; 222 DbRows.Free; 223 end; 224 end; 225 226 function TChronisBase.AddObjectGroup(Name: string): Integer; 227 var 228 DbRows: TDbRows; 229 Data: TDictionaryStringString; 230 begin 231 try 232 DbRows := TDbRows.Create; 233 Data := TDictionaryStringString.Create; 234 Data.Add('Name', Name); 235 Database.Insert(ObjectGroupTable, Data); 236 Result := Database.LastInsertId; 237 finally 238 Data.Free; 239 DbRows.Free; 240 end; 241 end; 242 151 243 constructor TChronisBase.Create; 152 244 begin … … 184 276 try 185 277 DbRows := TDbRows.Create; 186 Base.Database.Query(DbRows, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(ObjectId)); 278 Base.Database.Query(DbRows, 'SELECT * FROM `' + ObjectTable + 279 '` WHERE `Id`=' + IntToStr(ObjectId)); 187 280 if DbRows.Count = 1 then begin 188 281 Id := ObjectId;
Note:
See TracChangeset
for help on using the changeset viewer.