Changeset 43 for trunk/Module
- Timestamp:
- Mar 9, 2012, 1:09:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Module/UModuleSystem.pas
r37 r43 149 149 150 150 procedure TModuleSystem.InitStructure; 151 var 152 StructureVersion: string; 153 Data: TDictionaryStringString; 154 ObjectId: Integer; 155 Tables: TListString; 156 I: Integer; 157 NewProxy: TListProxy; 158 begin 159 with TChronisBase(System) do 151 begin 152 with TChronisBase(System).Client do 160 153 try 161 Tables := TListString.Create; 162 Data := TDictionaryStringString.Create; 163 164 NewProxy := TListProxy.Create; 165 NewProxy.SchemaName := 'information_schema'; 166 NewProxy.ObjectName := 'TABLES'; 167 NewProxy.Condition := 'TABLE_SCHEMA = "' + Client.Schema + '"'; 168 NewProxy.Load; 169 //Database.Query(DbRows, 'SHOW TABLES'); 170 Tables.Count := NewProxy.Objects.Count; 171 for I := 0 to NewProxy.Objects.Count - 1 do 172 Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Values['TABLE']; 173 174 (* if Tables.IndexOf(ObjectTable) = -1 then begin 175 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectTable + '` ( ' + 176 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 177 '`Name` varchar(255) NOT NULL,' + 178 '`Schema` varchar(255) NOT NULL,' + 179 '`Table` varchar(255) NOT NULL,' + 180 '`PrimaryKey` varchar(255) NOT NULL DEFAULT "Id", ' + 181 '`Sequence` int(11) NOT NULL DEFAULT 0,' + 182 '`Group` int(11) NOT NULL,' + 183 'KEY `Group` (`Group`),' + 184 'PRIMARY KEY (`Id`)' + 185 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 186 187 end; 188 189 if Tables.IndexOf(ObjectGroupTable) = -1 then begin 190 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectGroupTable + '` ( ' + 191 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 192 '`Name` varchar(255) NOT NULL,' + 193 '`Parent` int(11) NOT NULL DEFAULT 0,' + 194 '`Sequence` int(11) NOT NULL DEFAULT 0,' + 195 'KEY `Parent` (`Parent`),' + 196 'PRIMARY KEY (`Id`)' + 197 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 198 end; 199 200 if Tables.IndexOf(PropertyTable) = -1 then begin 201 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTable + '` ( ' + 202 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 203 '`Name` varchar(255) NOT NULL,' + 204 '`Object` int(11) NOT NULL,' + 205 '`PropertyGroup` int(11) NOT NULL DEFAULT 0,' + 206 '`CustomType` int(11) NOT NULL,' + 207 '`Editable` bool NOT NULL DEFAULT 1,' + 208 '`ColumnName` varchar(255) NOT NULL,' + 209 'KEY `Object` (`Object`),' + 210 'KEY `PropertyGroup` (`PropertyGroup`),' + 211 'KEY `CustomType` (`CustomType`),' + 212 'PRIMARY KEY (`Id`)' + 213 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 214 end; 215 if Tables.IndexOf(PropertyTypeTable) = -1 then begin 216 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTypeTable + '` ( ' + 217 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 218 '`Name` varchar(255) NOT NULL,' + 219 '`DbType` varchar(255) NOT NULL,' + 220 'PRIMARY KEY (`Id`)' + 221 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 222 end; 223 224 if Tables.IndexOf(PropertyGroupTable) = -1 then begin 225 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyGroupTable + '` ( ' + 226 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 227 '`Name` varchar(255) NOT NULL,' + 228 '`Object` int(11) NOT NULL,' + 229 'KEY `Object` (`Object`),' + 230 'PRIMARY KEY (`Id`)' + 231 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 232 end; 233 234 if Tables.IndexOf(EnumerationState) = -1 then begin 235 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + EnumerationState + '` ( ' + 236 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 237 '`Enumeration` int(11) NOT NULL,' + 238 '`Name` varchar(255) NOT NULL,' + 239 '`Sequence` int(11) NOT NULL DEFAULT 0,' + 240 'KEY `Enumeration` (`Enumeration`),' + 241 'PRIMARY KEY (`Id`)' + 242 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 243 end; 244 245 if Tables.IndexOf(Enumeration) = -1 then begin 246 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + Enumeration + '` ( ' + 247 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 248 '`Name` varchar(255) NOT NULL,' + 249 'PRIMARY KEY (`Id`)' + 250 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 251 end; 252 253 if Tables.IndexOf(TypeEnumeration) = -1 then begin 254 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeEnumeration + '` ( ' + 255 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 256 '`Enumeration` int(11) NOT NULL,' + 257 'KEY `Enumeration` (`Enumeration`),' + 258 'PRIMARY KEY (`Id`)' + 259 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 260 end; 261 262 if Tables.IndexOf(TypeRelationOne) = -1 then begin 263 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeRelationOne + '` ( ' + 264 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 265 '`CustomType` int(11) NOT NULL,' + 266 '`Object` int(11) NOT NULL,' + 267 'KEY `CustomType` (`CustomType`),' + 268 'PRIMARY KEY (`Id`)' + 269 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 270 end; 271 272 if Tables.IndexOf(TypeRelationMany) = -1 then begin 273 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeRelationMany + '` ( ' + 274 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 275 '`CustomType` int(11) NOT NULL,' + 276 '`ObjectProperty` int(11) NOT NULL,' + 277 'KEY `CustomType` (`CustomType`),' + 278 'PRIMARY KEY (`Id`)' + 279 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 280 end; 281 282 if Tables.IndexOf(TypeFile) = -1 then begin 283 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeFile + '` ( ' + 284 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 285 '`Name` varchar(255) NOT NULL,' + 286 '`Size` int(11) NOT NULL,' + 287 'PRIMARY KEY (`Id`)' + 288 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 289 end; 290 291 if Tables.IndexOf(TypeGPS) = -1 then begin 292 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeGPS + '` ( ' + 293 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 294 '`Latitude` double NOT NULL,' + 295 '`Longitude` double NOT NULL,' + 296 'PRIMARY KEY (`Id`)' + 297 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 298 end; 299 300 if Tables.IndexOf(CustomTypeTableName) = -1 then begin 301 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + CustomTypeTableName + '` ( ' + 302 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 303 '`Type` int NOT NULL,' + 304 'KEY `Type` (`Type`),' + 305 'PRIMARY KEY (`Id`)' + 306 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 307 end; 308 309 if Tables.IndexOf(TypeNumber) = -1 then begin 310 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeNumber + '` ( ' + 311 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 312 '`CustomType` int NOT NULL,' + 313 '`Default` int NOT NULL,' + 314 '`Min` int NOT NULL,' + 315 '`Max` int NOT NULL,' + 316 'KEY `CustomType` (`CustomType`),' + 317 'PRIMARY KEY (`Id`)' + 318 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 319 end; 320 321 if Tables.IndexOf(TypeFloat) = -1 then begin 322 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeFloat + '` ( ' + 323 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 324 '`CustomType` int NOT NULL,' + 325 '`Default` float NOT NULL,' + 326 '`Min` float NOT NULL,' + 327 '`Max` float NOT NULL,' + 328 'KEY `CustomType` (`CustomType`),' + 329 'PRIMARY KEY (`Id`)' + 330 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 331 end; 332 333 if Tables.IndexOf(TypeDateTime) = -1 then begin 334 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeDateTime + '` ( ' + 335 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 336 '`CustomType` int NOT NULL,' + 337 '`Default` datetime NOT NULL,' + 338 '`Min` datetime NOT NULL,' + 339 '`Max` datetime NOT NULL,' + 340 'KEY `CustomType` (`CustomType`),' + 341 'PRIMARY KEY (`Id`)' + 342 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 343 end; 344 345 if Tables.IndexOf(TypeString) = -1 then begin 346 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeString + '` ( ' + 347 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 348 '`CustomType` int NOT NULL,' + 349 '`Default` VARCHAR(255) NOT NULL,' + 350 '`MaxLength` int NOT NULL,' + 351 'KEY `CustomType` (`CustomType`),' + 352 'PRIMARY KEY (`Id`)' + 353 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 354 end; 355 356 if Tables.IndexOf(ModuleTable) = -1 then begin 357 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ModuleTable + '` ( ' + 358 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 359 '`Name` VARCHAR(255) NOT NULL,' + 360 '`Author` VARCHAR(255) NOT NULL,' + 361 '`Website` VARCHAR(255) NOT NULL,' + 362 '`Version` VARCHAR(255) NOT NULL,' + 363 '`License` VARCHAR(255) NOT NULL,' + 364 '`Description` TEXT NOT NULL,' + 365 'PRIMARY KEY (`Id`)' + 366 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 367 end; *) 154 with Types.AddType(ObjectTable) do begin 155 with Properties do begin 156 Add('Name', 'String'); 157 Add('Schema', 'String'); 158 Add('Table', 'String'); 159 Add('PrimaryKey', 'String'); 160 Add('Sequence', 'Integer'); 161 Add('Group', 'RelationOne'); 162 end; 163 end; 164 165 with Types.AddType(ObjectGroupTable) do begin 166 with Properties do begin 167 Add('Name', 'String'); 168 Add('Schema', 'String'); 169 Add('Parent', 'RelationOne'); 170 Add('Sequence', 'Integer'); 171 end; 172 end; 173 174 with Types.AddType(PropertyTable) do begin 175 with Properties do begin 176 Add('Name', 'String'); 177 Add('Object', 'RelationOne'); 178 Add('PropertyGroup', 'RelationOne'); 179 Add('CustomType', 'RelationOne'); 180 Add('Editable', 'Boolean'); 181 Add('ColumnName', 'String'); 182 end; 183 end; 184 185 with Types.AddType(PropertyTypeTable) do begin 186 with Properties do begin 187 Add('Name', 'String'); 188 Add('DbType', 'String'); 189 end; 190 end; 191 192 with Types.AddType(PropertyGroupTable) do begin 193 with Properties do begin 194 Add('Name', 'String'); 195 Add('Object', 'RelationOne'); 196 end; 197 end; 198 199 with Types.AddType(EnumerationState) do begin 200 with Properties do begin 201 Add('Enumeration', 'RelationOne'); 202 Add('Name', 'String'); 203 Add('Sequence', 'Integer'); 204 end; 205 end; 206 207 with Types.AddType(Enumeration) do begin 208 with Properties do begin 209 Add('Name', 'String'); 210 end; 211 end; 212 213 with Types.AddType(TypeEnumeration) do begin 214 with Properties do begin 215 Add('Enumeration', 'RelationOne'); 216 end; 217 end; 218 219 with Types.AddType(TypeRelationOne) do begin 220 with Properties do begin 221 Add('CustomType', 'RelationOne'); 222 Add('Object', 'Integer'); 223 end; 224 end; 225 226 with Types.AddType(TypeRelationMany) do begin 227 with Properties do begin 228 Add('CustomType', 'RelationOne'); 229 Add('ObjectProperty', 'Integer'); 230 end; 231 end; 232 233 with Types.AddType(TypeFile) do begin 234 with Properties do begin 235 Add('Name', 'String'); 236 Add('Size', 'Integer'); 237 end; 238 end; 239 240 with Types.AddType(TypeGPS) do begin 241 with Properties do begin 242 Add('Latitude', 'Double'); 243 Add('Longitude', 'Double'); 244 end; 245 end; 246 247 with Types.AddType(CustomTypeTableName) do begin 248 with Properties do begin 249 Add('Type', 'RelationOne'); 250 end; 251 end; 252 253 with Types.AddType(TypeNumber) do begin 254 with Properties do begin 255 Add('CustomType', 'RelationOne'); 256 Add('Default', 'Integer'); 257 Add('Min', 'Integer'); 258 Add('Max', 'Integer'); 259 end; 260 end; 261 262 with Types.AddType(TypeFloat) do begin 263 with Properties do begin 264 Add('CustomType', 'RelationOne'); 265 Add('Default', 'Double'); 266 Add('Min', 'Double'); 267 Add('Max', 'Double'); 268 end; 269 end; 270 271 with Types.AddType(TypeDateTime) do begin 272 with Properties do begin 273 Add('CustomType', 'RelationOne'); 274 Add('Default', 'DateTime'); 275 Add('Min', 'DateTime'); 276 Add('Max', 'DateTime'); 277 end; 278 end; 279 280 with Types.AddType(TypeString) do begin 281 with Properties do begin 282 Add('CustomType', 'RelationOne'); 283 Add('Default', 'String'); 284 Add('MaxLength', 'Integer'); 285 end; 286 end; 287 288 with Types.AddType(ModuleTable) do begin 289 with Properties do begin 290 Add('Name', 'String'); 291 Add('Author', 'String'); 292 Add('Website', 'String'); 293 Add('Version', 'String'); 294 Add('License', 'String'); 295 Add('Description', 'Text'); 296 end; 297 end; 298 299 CheckTypes; 368 300 finally 369 Tables.Free;370 Data.Free;371 NewProxy.Free;372 301 end; 373 302 end;
Note:
See TracChangeset
for help on using the changeset viewer.