Changeset 37 for trunk/USystem.pas
- Timestamp:
- Mar 8, 2012, 3:11:10 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/USystem.pas
r35 r37 106 106 Types: TChronisTypeList; 107 107 Client: TChronisClient; 108 Database: TSqlDatabase;108 //Database: TSqlDatabase; 109 109 Modules: TListObject; // TListObject<TChronisModule> 110 110 ModuleSystem: TChronisModule; … … 207 207 Properties.Client := Base.Client; 208 208 Properties.ObjectName := PropertyTable; 209 Properties.SchemaName := Base. Database.Database;210 Properties. SetCondition('Object', IntToStr(Obj.Id));209 Properties.SchemaName := Base.Client.Schema; 210 Properties.Condition := 'Object="' + IntToStr(Obj.Id) + '"'; 211 211 Properties.Load; 212 212 Columns.Clear; … … 262 262 function TChronisBase.AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer; 263 263 var 264 DbRows: TDbRows; 265 Data: TDictionaryStringString; 266 begin 267 try 268 DbRows := TDbRows.Create; 269 Data := TDictionaryStringString.Create; 270 Data.Add('Name', Name); 271 Data.Add('DbType', DataType); 272 Data.Add('Id', IntToStr(Integer(TypeIndex))); 273 Database.Insert(PropertyTypeTable, Data); 274 Result := Database.LastInsertId; 275 finally 276 Data.Free; 277 DbRows.Free; 264 Proxy: TObjectProxy; 265 begin 266 try 267 Proxy := TObjectProxy.Create; 268 Proxy.Client := Client; 269 Proxy.ObjectName := PropertyTypeTable; 270 Proxy.Properties.Add('Name', Name); 271 Proxy.Properties.Add('DbType', DataType); 272 Proxy.Properties.Add('Id', IntToStr(Integer(TypeIndex))); 273 Proxy.Save; 274 Result := Proxy.Id; 275 finally 276 Proxy.Free; 278 277 end; 279 278 end; … … 281 280 function TChronisBase.AddGroup(Name: string; ParentGroupId: Integer): Integer; 282 281 var 283 DbRows: TDbRows; 284 Data: TDictionaryStringString; 285 begin 286 try 287 DbRows := TDbRows.Create; 288 Data := TDictionaryStringString.Create; 289 Data.Add('Name', Name); 290 Data.Add('Parent', IntToStr(ParentGroupId)); 291 Database.Insert(ObjectGroupTable, Data); 292 Result := Database.LastInsertId; 293 finally 294 Data.Free; 295 DbRows.Free; 282 Proxy: TObjectProxy; 283 begin 284 try 285 Proxy := TObjectProxy.Create; 286 Proxy.Client := Client; 287 Proxy.ObjectName := ObjectGroupTable; 288 Proxy.Properties.Add('Name', Name); 289 Proxy.Properties.Add('Parent', IntToStr(ParentGroupId)); 290 Proxy.Save; 291 Result := Proxy.Id; 292 finally 293 Proxy.Free; 296 294 end; 297 295 end; … … 300 298 GroupId: Integer): Integer; 301 299 var 302 DbRows: TDbRows; 303 Data: TDictionaryStringString; 304 begin 305 try 306 DbRows := TDbRows.Create; 307 Data := TDictionaryStringString.Create; 308 Data.Add('Name', Name); 309 Data.Add('Schema', Schema); 310 Data.Add('Table', TableName); 311 Data.Add('Group', IntToStr(GroupId)); 312 Database.Insert(ObjectTable, Data); 313 Result := Database.LastInsertId; 314 finally 315 Data.Free; 316 DbRows.Free; 300 Proxy: TObjectProxy; 301 begin 302 try 303 Proxy := TObjectProxy.Create; 304 Proxy.Client := Client; 305 Proxy.ObjectName := ObjectTable; 306 Proxy.Properties.Add('Name', Name); 307 Proxy.Properties.Add('Schema', Schema); 308 Proxy.Properties.Add('Table', TableName); 309 Proxy.Properties.Add('Group', IntToStr(GroupId)); 310 Proxy.Save; 311 Result := Proxy.Id; 312 finally 313 Proxy.Free; 317 314 end; 318 315 end; … … 321 318 CustomType: Integer; Editable: Boolean): Integer; 322 319 var 323 DbRows: TDbRows; 324 Data: TDictionaryStringString; 325 begin 326 try 327 DbRows := TDbRows.Create; 328 Data := TDictionaryStringString.Create; 329 Data.Add('Name', Name); 330 Data.Add('Object', IntToStr(ObjectId)); 331 Data.Add('ColumnName', ColumnName); 332 Data.Add('CustomType', IntToStr(CustomType)); 333 Data.Add('Editable', IntToStr(Integer(Editable))); 334 Database.Insert(PropertyTable, Data); 335 Result := Database.LastInsertId; 336 finally 337 Data.Free; 338 DbRows.Free; 320 Proxy: TObjectProxy; 321 begin 322 try 323 Proxy := TObjectProxy.Create; 324 Proxy.Client := Client; 325 Proxy.ObjectName := PropertyTable; 326 Proxy.Properties.Add('Name', Name); 327 Proxy.Properties.Add('Object', IntToStr(ObjectId)); 328 Proxy.Properties.Add('ColumnName', ColumnName); 329 Proxy.Properties.Add('CustomType', IntToStr(CustomType)); 330 Proxy.Properties.Add('Editable', IntToStr(Integer(Editable))); 331 Proxy.Save; 332 Result := Proxy.Id; 333 finally 334 Proxy.Free; 339 335 end; 340 336 end; … … 344 340 Max: Integer = High(Integer)): Integer; 345 341 var 346 DbRows: TDbRows; 347 Data: TDictionaryStringString; 342 Proxy: TObjectProxy; 348 343 CustomTypeId: Integer; 349 344 begin 350 345 try 351 DbRows := TDbRows.Create; 352 Data := TDictionaryStringString.Create; 353 354 Data.Clear; 355 Data.Add('Type', IntToStr(Integer(vtInteger))); 356 Database.Insert(CustomTypeTableName, Data); 357 CustomTypeId := Database.LastInsertId; 358 359 Data.Clear; 360 Data.Add('CustomType', IntToStr(CustomTypeId)); 361 Data.Add('Min', IntToStr(Min)); 362 Data.Add('Max', IntToStr(Max)); 363 Data.Add('Default', IntToStr(Default)); 364 Database.Insert(TypeNumber, Data); 346 Proxy := TObjectProxy.Create; 347 Proxy.Client := Client; 348 Proxy.ObjectName := CustomTypeTableName; 349 Proxy.Properties.Add('Type', IntToStr(Integer(vtInteger))); 350 CustomTypeId := Proxy.Id; 351 352 Proxy.ObjectName := TypeNumber; 353 Proxy.Properties.Clear; 354 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 355 Proxy.Properties.Add('Min', IntToStr(Min)); 356 Proxy.Properties.Add('Max', IntToStr(Max)); 357 Proxy.Properties.Add('Default', IntToStr(Default)); 358 Proxy.Save; 365 359 //CustomTypeId := Database.LastInsertId; 366 360 367 361 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 368 finally369 Data.Free;370 DbRows.Free;362 Result := Proxy.Id; 363 finally 364 Proxy.Free; 371 365 end; 372 366 end; … … 375 369 ColumnName: string; Editable: Boolean; Default: Double; Min: Double; Max: Double): Integer; 376 370 var 377 DbRows: TDbRows; 378 Data: TDictionaryStringString; 371 Proxy: TObjectProxy; 379 372 CustomTypeId: Integer; 380 373 begin 381 374 try 382 DbRows := TDbRows.Create; 383 Data := TDictionaryStringString.Create; 384 385 Data.Clear; 386 Data.Add('Type', IntToStr(Integer(vtFloat))); 387 Database.Insert(CustomTypeTableName, Data); 388 CustomTypeId := Database.LastInsertId; 389 390 Data.Clear; 391 Data.Add('CustomType', IntToStr(CustomTypeId)); 392 Data.Add('Min', MySQLFloatToStr(Min)); 393 Data.Add('Max', MySQLFloatToStr(Max)); 394 Data.Add('Default', MySQLFloatToStr(Default)); 395 Database.Insert(TypeFloat, Data); 375 Proxy := TObjectProxy.Create; 376 Proxy.Client := Client; 377 Proxy.ObjectName := CustomTypeTableName; 378 Proxy.Properties.Add('Type', IntToStr(Integer(vtFloat))); 379 CustomTypeId := Proxy.Id; 380 381 Proxy.ObjectName := TypeFloat; 382 Proxy.Properties.Clear; 383 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 384 Proxy.Properties.Add('Min', MySQLFloatToStr(Min)); 385 Proxy.Properties.Add('Max', MySQLFloatToStr(Max)); 386 Proxy.Properties.Add('Default', MySQLFloatToStr(Default)); 387 Proxy.Save; 396 388 //CustomTypeId := Database.LastInsertId; 397 389 398 390 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 399 391 finally 400 Data.Free; 401 DbRows.Free; 392 Proxy.Free; 402 393 end; 403 394 end; … … 407 398 ): Integer; 408 399 var 409 DbRows: TDbRows; 410 Data: TDictionaryStringString; 400 Proxy: TObjectProxy; 411 401 CustomTypeId: Integer; 412 402 begin 413 403 try 414 DbRows := TDbRows.Create;415 Data := TDictionaryStringString.Create;416 417 Data.Clear;418 Data.Add('Type', IntToStr(Integer(vtDateTime)));419 Database.Insert(CustomTypeTableName, Data);420 CustomTypeId := Database.LastInsertId; 421 422 Data.Clear;423 Data.Add('CustomType', IntToStr(CustomTypeId));424 Data.Add('Min', DateTimeToSQL(Min));425 Data.Add('Max', DateTimeToSQL(Max));426 Data.Add('Default', DateTimeToSQL(Default));427 Database.Insert(TypeDateTime, Data);404 Proxy := TObjectProxy.Create; 405 Proxy.Client := Client; 406 Proxy.ObjectName := CustomTypeTableName; 407 Proxy.Properties.Add('Type', IntToStr(Integer(vtDateTime))); 408 Proxy.Save; 409 CustomTypeId := Proxy.Id; 410 411 Proxy.ObjectName := TypeDateTime; 412 Proxy.Properties.Clear; 413 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 414 Proxy.Properties.Add('Min', DateTimeToSQL(Min)); 415 Proxy.Properties.Add('Max', DateTimeToSQL(Max)); 416 Proxy.Properties.Add('Default', DateTimeToSQL(Default)); 417 Proxy.Save; 428 418 //CustomTypeId := Database.LastInsertId; 429 419 430 420 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 431 421 finally 432 Data.Free; 433 DbRows.Free; 422 Proxy.Free; 434 423 end; 435 424 end; … … 438 427 ColumnName: string; Editable: Boolean; Default: string = ''; MaxLength: Integer = 255): Integer; 439 428 var 440 DbRows: TDbRows; 441 Data: TDictionaryStringString; 429 Proxy: TObjectProxy; 442 430 CustomTypeId: Integer; 443 431 begin 444 432 try 445 DbRows := TDbRows.Create;446 Data := TDictionaryStringString.Create;447 448 Data.Clear;449 Data.Add('Type', IntToStr(Integer(vtString)));450 Database.Insert(CustomTypeTableName, Data);451 CustomTypeId := Database.LastInsertId; 452 453 Data.Clear;454 Data.Add('CustomType', IntToStr(CustomTypeId));455 Data.Add('MaxLength', IntToStr(MaxLength));456 Data.Add('Default', Default);457 Database.Insert(TypeString, Data);433 Proxy := TObjectProxy.Create; 434 Proxy.Client := Client; 435 Proxy.ObjectName := CustomTypeTableName; 436 Proxy.Properties.Add('Type', IntToStr(Integer(vtString))); 437 Proxy.Save; 438 CustomTypeId := Proxy.Id; 439 440 Proxy.ObjectName := TypeString; 441 Proxy.Properties.Clear; 442 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 443 Proxy.Properties.Add('MaxLength', IntToStr(MaxLength)); 444 Proxy.Properties.Add('Default', Default); 445 Proxy.Save; 458 446 //CustomTypeId := Database.LastInsertId; 459 447 460 448 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 461 449 finally 462 Data.Free; 463 DbRows.Free; 450 Proxy.Free; 464 451 end; 465 452 end; … … 468 455 ColumnName: string; Editable: Boolean; Default: string): Integer; 469 456 var 470 DbRows: TDbRows; 471 Data: TDictionaryStringString; 457 Proxy: TObjectProxy; 472 458 CustomTypeId: Integer; 473 459 begin 474 460 try 475 DbRows := TDbRows.Create;476 Data := TDictionaryStringString.Create;477 478 Data.Clear;479 Data.Add('Type', IntToStr(Integer(vtText)));480 Database.Insert(CustomTypeTableName, Data);481 CustomTypeId := Database.LastInsertId; 482 483 Data.Clear;484 Data.Add('CustomType', IntToStr(CustomTypeId));485 Data.Add('Default', Default);486 Database.Insert(TypeString, Data);461 Proxy := TObjectProxy.Create; 462 Proxy.Client := Client; 463 Proxy.ObjectName := CustomTypeTableName; 464 Proxy.Properties.Add('Type', IntToStr(Integer(vtText))); 465 Proxy.Save; 466 CustomTypeId := Proxy.Id; 467 468 Proxy.ObjectName := TypeString; 469 Proxy.Properties.Clear; 470 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 471 Proxy.Properties.Add('Default', Default); 472 Proxy.Save; 487 473 //CustomTypeId := Database.LastInsertId; 488 474 489 475 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 490 476 finally 491 Data.Free; 492 DbRows.Free; 477 Proxy.Free; 493 478 end; 494 479 end; … … 497 482 ColumnName: string; Editable: Boolean; ReferedObject: Integer): Integer; 498 483 var 499 DbRows: TDbRows; 500 Data: TDictionaryStringString; 484 Proxy: TObjectProxy; 501 485 CustomTypeId: Integer; 502 486 begin 503 487 try 504 DbRows := TDbRows.Create;505 Data := TDictionaryStringString.Create;506 507 Data.Clear;508 Data.Add('Type', IntToStr(Integer(vtRelationOne)));509 Database.Insert(CustomTypeTableName, Data);510 CustomTypeId := Database.LastInsertId; 511 512 Data.Clear;513 Data.Add('CustomType', IntToStr(CustomTypeId));514 Data.Add('Object', IntToStr(ReferedObject));515 Database.Insert(TypeRelationOne, Data);488 Proxy := TObjectProxy.Create; 489 Proxy.Client := Client; 490 Proxy.ObjectName := CustomTypeTableName; 491 Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationOne))); 492 Proxy.Save; 493 CustomTypeId := Proxy.Id; 494 495 Proxy.ObjectName := TypeRelationOne; 496 Proxy.Properties.Clear; 497 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 498 Proxy.Properties.Add('Object', IntToStr(ReferedObject)); 499 Proxy.Save; 516 500 //CustomTypeId := Database.LastInsertId; 517 501 518 502 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 519 503 finally 520 Data.Free; 521 DbRows.Free; 504 Proxy.Free; 522 505 end; 523 506 end; … … 526 509 ColumnName: string; Editable: Boolean; ReferedObjectProperty: Integer): Integer; 527 510 var 528 DbRows: TDbRows; 529 Data: TDictionaryStringString; 511 Proxy: TObjectProxy; 530 512 CustomTypeId: Integer; 531 513 begin 532 514 try 533 DbRows := TDbRows.Create; 534 Data := TDictionaryStringString.Create; 535 536 Data.Clear; 537 Data.Add('Type', IntToStr(Integer(vtRelationMany))); 538 Database.Insert(CustomTypeTableName, Data); 539 CustomTypeId := Database.LastInsertId; 540 541 Data.Clear; 542 Data.Add('CustomType', IntToStr(CustomTypeId)); 543 Data.Add('ObjectProperty', IntToStr(ReferedObjectProperty)); 544 Database.Insert(TypeRelationMany, Data); 515 Proxy := TObjectProxy.Create; 516 Proxy.Client := Client; 517 Proxy.ObjectName := CustomTypeTableName; 518 519 Proxy.Properties.Clear; 520 Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationMany))); 521 Proxy.Save; 522 CustomTypeId := Proxy.Id; 523 524 Proxy.ObjectName := TypeRelationMany; 525 Proxy.Properties.Clear; 526 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 527 Proxy.Properties.Add('ObjectProperty', IntToStr(ReferedObjectProperty)); 528 Proxy.Save; 545 529 //CustomTypeId := Database.LastInsertId; 546 530 547 531 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 548 532 finally 549 Data.Free; 550 DbRows.Free; 533 Proxy.Free; 551 534 end; 552 535 end; … … 554 537 function TChronisBase.AddObjectGroup(Name: string): Integer; 555 538 var 556 DbRows: TDbRows; 557 Data: TDictionaryStringString; 558 begin 559 try 560 DbRows := TDbRows.Create; 561 Data := TDictionaryStringString.Create; 562 Data.Add('Name', Name); 563 Database.Insert(ObjectGroupTable, Data); 564 Result := Database.LastInsertId; 565 finally 566 Data.Free; 567 DbRows.Free; 539 Proxy: TObjectProxy; 540 begin 541 try 542 Proxy := TObjectProxy.Create; 543 Proxy.Client := Client; 544 Proxy.ObjectName := ObjectGroupTable; 545 Proxy.Properties.Add('Name', Name); 546 Proxy.Save; 547 Result := Proxy.Id; 548 finally 549 Proxy.Free; 568 550 end; 569 551 end; … … 571 553 function TChronisBase.AddEnumeration(Name: string): Integer; 572 554 var 573 DbRows: TDbRows; 574 Data: TDictionaryStringString; 575 begin 576 try 577 DbRows := TDbRows.Create; 578 Data := TDictionaryStringString.Create; 579 Data.Add('Name', Name); 580 Database.Insert(Enumeration, Data); 581 Result := Database.LastInsertId; 582 finally 583 Data.Free; 584 DbRows.Free; 555 Proxy: TObjectProxy; 556 begin 557 try 558 Proxy := TObjectProxy.Create; 559 Proxy.Client := Client; 560 Proxy.ObjectName := Enumeration; 561 Proxy.Properties.Add('Name', Name); 562 Proxy.Save; 563 Result := Proxy.Id; 564 finally 565 Proxy.Free; 585 566 end; 586 567 end; … … 589 570 ): Integer; 590 571 var 591 DbRows: TDbRows; 592 Data: TDictionaryStringString; 593 begin 594 try 595 DbRows := TDbRows.Create; 596 Data := TDictionaryStringString.Create; 597 Data.Add('Enumeration', IntToStr(Enum)); 598 Data.Add('Name', Name); 599 Database.Insert(EnumerationState, Data); 600 Result := Database.LastInsertId; 601 finally 602 Data.Free; 603 DbRows.Free; 572 Proxy: TObjectProxy; 573 begin 574 try 575 Proxy := TObjectProxy.Create; 576 Proxy.Client := Client; 577 Proxy.ObjectName := EnumerationState; 578 Proxy.Properties.Add('Enumeration', IntToStr(Enum)); 579 Proxy.Properties.Add('Name', Name); 580 Proxy.Save; 581 Result := Proxy.Id; 582 finally 583 Proxy.Free; 604 584 end; 605 585 end; … … 608 588 License: string): Integer; 609 589 var 610 DbRows: TDbRows; 611 Data: TDictionaryStringString; 612 begin 613 try 614 DbRows := TDbRows.Create; 615 Data := TDictionaryStringString.Create; 616 Data.Add('Name', Name); 617 Data.Add('Author', Author); 618 Data.Add('Website', Website); 619 Data.Add('Version', Version); 620 Data.Add('Description', Description); 621 Data.Add('License', License); 622 Database.Insert(ModuleTable, Data); 623 Result := Database.LastInsertId; 624 finally 625 Data.Free; 626 DbRows.Free; 590 Proxy: TObjectProxy; 591 begin 592 try 593 Proxy := TObjectProxy.Create; 594 Proxy.Client := Client; 595 Proxy.ObjectName := ModuleTable; 596 Proxy.Properties.Add('Name', Name); 597 Proxy.Properties.Add('Author', Author); 598 Proxy.Properties.Add('Website', Website); 599 Proxy.Properties.Add('Version', Version); 600 Proxy.Properties.Add('Description', Description); 601 Proxy.Properties.Add('License', License); 602 Proxy.Save; 603 Result := Proxy.Id; 604 finally 605 Proxy.Free; 627 606 end; 628 607 end; … … 630 609 procedure TChronisBase.LoadTypes; 631 610 var 632 DbRows: TDbRows;611 Proxy: TListProxy; 633 612 I: Integer; 634 613 begin 635 614 try 636 DbRows := TDbRows.Create; 615 Proxy := TListProxy.Create; 616 Proxy.Client := Client; 617 Proxy.ObjectName := PropertyTypeTable; 618 Proxy.Load; 637 619 Types.Clear; 638 Database.Select(DbRows, PropertyTypeTable); 639 for I := 0 to DbRows.Count - 1 do begin 620 for I := 0 to Proxy.Objects.Count - 1 do begin 640 621 with TChronisType(Types.AddNew(TChronisType.Create)) do 641 with DbRows[I]do begin642 Id := StrToInt( Values['Id']);643 DbType := Values['DbType'];644 //Parent := StrToInt( Values['Parent']);622 with TObjectProxy(Proxy.Objects[I]) do begin 623 Id := StrToInt(Properties.Values['Id']); 624 DbType := Properties.Values['DbType']; 625 //Parent := StrToInt(Properties.Values['Parent']); 645 626 end; 646 627 end; 647 628 finally 648 DbRows.Free;629 Proxy.Free; 649 630 end; 650 631 end; … … 652 633 function TChronisBase.IsDatabaseEmpty: Boolean; 653 634 var 654 DbRows: TDbRows; 655 begin 656 try 657 DbRows := TDbRows.Create; 658 Database.Query(DbRows, 'SELECT 1 FROM information_schema.tables WHERE table_name = "Information" AND table_schema = "' + 659 Database.Database + '"'); 660 Result := DbRows.Count = 0; 661 finally 662 DbRows.Free; 635 Proxy: TListProxy; 636 begin 637 try 638 Proxy := TListProxy.Create; 639 Proxy.Client := Client; 640 Proxy.SchemaName := 'information_schema'; 641 Proxy.ObjectName := 'tables'; 642 Proxy.Condition := 'table_name = "Information" AND table_schema = "' + 643 Client.Schema + '"'; 644 Proxy.Load; 645 Result := Proxy.Objects.Count = 0; 646 finally 647 Proxy.Free; 663 648 end; 664 649 end; … … 718 703 List.Client := Core.System.Client; 719 704 List.ObjectName := ObjectTable; 720 List.SchemaName := Core.System. Database.Database;721 List. SetCondition('Id', IntToStr(ObjectId));705 List.SchemaName := Core.System.Client.Schema; 706 List.Condition := 'Id=' + IntToStr(ObjectId); 722 707 List.Load; 723 708 if List.Objects.Count = 1 then begin
Note:
See TracChangeset
for help on using the changeset viewer.