Changeset 12 for trunk/DbEngines/UEngineMySQL.pas
- Timestamp:
- Feb 16, 2015, 11:37:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DbEngines/UEngineMySQL.pas
r7 r12 6 6 7 7 uses 8 Classes, SysUtils, UDatabase ;8 Classes, SysUtils, UDatabase, USqlDatabase, UHtmlClasses, SpecializedDictionary; 9 9 10 10 type 11 12 { TDatabaseMySQL } 13 11 14 TDatabaseMySQL = class(TDatabaseClient) 12 15 private 16 procedure LoadTables; 17 public 18 SqlDatabase: TSqlDatabase; 19 constructor Create; override; 20 destructor Destroy; override; 21 procedure Load; override; 22 procedure Save; override; 13 23 end; 14 24 15 25 implementation 16 26 27 { TDatabaseMySQL } 28 29 procedure TDatabaseMySQL.LoadTables; 30 var 31 DbRows: TDbRows; 32 NewTable: TTable; 33 I: Integer; 34 begin 35 DbRows := TDbRows.Create; 36 try 37 SqlDatabase.Query(DbRows, 'SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = "' + SqlDatabase.Database + '"'); 38 for I := 0 to DbRows.Count - 1 do begin 39 NewTable := TTable.Create; 40 NewTable.Database := Database; 41 NewTable.Name := (TDictionaryStringString(DbRows[I])[0]).Value; 42 NewTable.Caption := NewTable.Name; 43 Database.Tables.Add(NewTable); 44 end; 45 finally 46 DbRows.Free; 47 end; 48 end; 49 50 constructor TDatabaseMySQL.Create; 51 begin 52 inherited Create; 53 SqlDatabase := TSqlDatabase.Create(nil); 54 end; 55 56 destructor TDatabaseMySQL.Destroy; 57 begin 58 SqlDatabase.Free; 59 inherited Destroy; 60 end; 61 62 procedure TDatabaseMySQL.Load; 63 var 64 URL: TURL; 65 begin 66 URL := TURL.Create; 67 try 68 URL.AsString := Database.ConnectionString; 69 if URL.Scheme <> 'mysql' then 70 raise Exception.Create('Wrong connection string. Required mysql protocol.'); 71 72 SqlDatabase.HostName := URL.Host.AsString; 73 if URL.Port <> 0 then 74 SqlDatabase.Port := URL.Port; 75 SqlDatabase.UserName := URL.UserName; 76 SqlDatabase.Password := URL.Password; 77 if Copy(URL.Path, 1, 1) = '/' then 78 SqlDatabase.Database := Copy(URL.Path, 2, High(Integer)); 79 SqlDatabase.Connect; 80 LoadTables; 81 finally 82 URL.Free; 83 end; 84 inherited Load; 85 end; 86 87 procedure TDatabaseMySQL.Save; 88 begin 89 SqlDatabase.Disconnect; 90 inherited Save; 91 end; 92 17 93 end. 18 94
Note:
See TracChangeset
for help on using the changeset viewer.