Changeset 12 for trunk/DbEngines
- Timestamp:
- Feb 16, 2015, 11:37:47 PM (10 years ago)
- Location:
- trunk/DbEngines
- Files:
-
- 2 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 -
trunk/DbEngines/UEngineXML.pas
r8 r12 6 6 7 7 uses 8 Classes, SysUtils, DOM, XMLRead, XMLWrite, UDatabase, UXMLUtils, FileUtil; 8 Classes, SysUtils, DOM, XMLRead, XMLWrite, UDatabase, UXMLUtils, FileUtil, 9 UHtmlClasses; 9 10 10 11 type … … 46 47 47 48 function TDatabaseXML.GetFileName: string; 48 begin 49 if Copy(Database.ConnectionString, 1, 8) = 'file:///' then 50 Result := Copy(Database.ConnectionString, 8, High(Integer)) 51 else Result := ''; 49 var 50 URL: TURL; 51 begin 52 URL := TURL.Create; 53 try 54 URL.AsString := Database.ConnectionString; 55 if URL.Scheme <> 'file' then 56 raise Exception.Create('Wrong connection string. Required file scheme.'); 57 58 Result := URL.Path 59 finally 60 URL.Free; 61 end; 52 62 end; 53 63
Note:
See TracChangeset
for help on using the changeset viewer.