Changeset 13 for trunk/DbEngines/UEngineMySQL.pas
- Timestamp:
- Mar 17, 2015, 12:09:11 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DbEngines/UEngineMySQL.pas
r12 r13 14 14 TDatabaseMySQL = class(TDatabaseClient) 15 15 private 16 procedure LoadFields(Table: TTable); 16 17 procedure LoadTables; 17 18 public 18 19 SqlDatabase: TSqlDatabase; 20 procedure Query(DbRows: TDbRows; Text: string); override; 19 21 constructor Create; override; 20 22 destructor Destroy; override; … … 27 29 { TDatabaseMySQL } 28 30 31 procedure TDatabaseMySQL.LoadFields(Table: TTable); 32 var 33 DbRows: TDbRows; 34 NewField: TField; 35 I: Integer; 36 DataType: Integer; 37 begin 38 DbRows := TDbRows.Create; 39 try 40 SqlDatabase.Query(DbRows, 'SELECT * FROM `ModelField` WHERE `Model` = ' + IntToStr(Table.Id) + ''); 41 for I := 0 to DbRows.Count - 1 do begin 42 NewField := TField.Create; 43 NewField.Table := Table; 44 NewField.Name := TDictionaryStringString(DbRows[I]).Values['Name']; 45 NewField.TextBefore := TDictionaryStringString(DbRows[I]).Values['Title']; 46 DataType := StrToInt(TDictionaryStringString(DbRows[I]).Values['DataType']); 47 NewField.DataType := Table.Database.Engine.DataTypes.FindByType(TFieldType(DataType)); 48 if not Assigned(NewField.DataType) then 49 NewField.DataType := Table.Database.Engine.DataTypes.FindByType(ftString); 50 Table.Fields.Add(NewField); 51 end; 52 finally 53 DbRows.Free; 54 end; 55 end; 56 29 57 procedure TDatabaseMySQL.LoadTables; 30 58 var 31 59 DbRows: TDbRows; 60 DbRows2: TDbRows; 32 61 NewTable: TTable; 33 62 I: Integer; … … 35 64 DbRows := TDbRows.Create; 36 65 try 37 SqlDatabase.Query(DbRows, 'SELECT ` TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = "' + SqlDatabase.Database + '"');66 SqlDatabase.Query(DbRows, 'SELECT `Id`,`Name`,`Title` FROM `Model`'); 38 67 for I := 0 to DbRows.Count - 1 do begin 39 68 NewTable := TTable.Create; 69 NewTable.Id := StrToInt(TDictionaryStringString(DbRows[I]).Values['Id']); 40 70 NewTable.Database := Database; 41 NewTable.Name := (TDictionaryStringString(DbRows[I])[0]).Value; 42 NewTable.Caption := NewTable.Name; 71 NewTable.Name := TDictionaryStringString(DbRows[I]).Values['Name']; 72 NewTable.Caption := TDictionaryStringString(DbRows[I]).Values['Title']; 73 LoadFields(NewTable); 74 DbRows2 := TDbRows.Create; 75 try 76 SqlDatabase.Query(DbRows2, 'SELECT COUNT(*) FROM `' + NewTable.Name + '`'); 77 if DbRows2.Count = 1 then 78 NewTable.RecordsCount := StrToInt(DbRows2[0].Values['COUNT(*)']); 79 finally 80 DbRows2.Free; 81 end; 43 82 Database.Tables.Add(NewTable); 44 83 end; … … 46 85 DbRows.Free; 47 86 end; 87 end; 88 89 procedure TDatabaseMySQL.Query(DbRows: TDbRows; Text: string); 90 begin 91 SqlDatabase.Query(DbRows, Text); 48 92 end; 49 93
Note:
See TracChangeset
for help on using the changeset viewer.