Changeset 12


Ignore:
Timestamp:
Feb 16, 2015, 11:37:47 PM (10 years ago)
Author:
chronos
Message:
  • Added: Connection to MySQL host and loading list of available tables.
Location:
trunk
Files:
31 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/DbEngines/UEngineMySQL.pas

    r7 r12  
    66
    77uses
    8   Classes, SysUtils, UDatabase;
     8  Classes, SysUtils, UDatabase, USqlDatabase, UHtmlClasses, SpecializedDictionary;
    99
    1010type
     11
     12  { TDatabaseMySQL }
     13
    1114  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;
    1323  end;
    1424
    1525implementation
    1626
     27{ TDatabaseMySQL }
     28
     29procedure TDatabaseMySQL.LoadTables;
     30var
     31  DbRows: TDbRows;
     32  NewTable: TTable;
     33  I: Integer;
     34begin
     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;
     48end;
     49
     50constructor TDatabaseMySQL.Create;
     51begin
     52  inherited Create;
     53  SqlDatabase := TSqlDatabase.Create(nil);
     54end;
     55
     56destructor TDatabaseMySQL.Destroy;
     57begin
     58  SqlDatabase.Free;
     59  inherited Destroy;
     60end;
     61
     62procedure TDatabaseMySQL.Load;
     63var
     64  URL: TURL;
     65begin
     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;
     85end;
     86
     87procedure TDatabaseMySQL.Save;
     88begin
     89  SqlDatabase.Disconnect;
     90  inherited Save;
     91end;
     92
    1793end.
    1894
  • trunk/DbEngines/UEngineXML.pas

    r8 r12  
    66
    77uses
    8   Classes, SysUtils, DOM, XMLRead, XMLWrite, UDatabase, UXMLUtils, FileUtil;
     8  Classes, SysUtils, DOM, XMLRead, XMLWrite, UDatabase, UXMLUtils, FileUtil,
     9  UHtmlClasses;
    910
    1011type
     
    4647
    4748function 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 := '';
     49var
     50  URL: TURL;
     51begin
     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;
    5262end;
    5363
  • trunk/Languages/MyData.cs.po

    r11 r12  
    400400msgid "Do you want to really remove table '%s' ?"
    401401msgstr "Opravdu chcete odstranit tabulku '%s'?"
     402
     403#: usqldatabase.sdatabasequeryerror
     404msgid "Database query error: \"%s\""
     405msgstr ""
     406
  • trunk/Languages/MyData.po

    r11 r12  
    392392msgstr ""
    393393
     394#: usqldatabase.sdatabasequeryerror
     395msgid "Database query error: \"%s\""
     396msgstr ""
     397
  • trunk/MyData.lpi

    r10 r12  
    6868      </local>
    6969    </RunParams>
    70     <RequiredPackages Count="5">
     70    <RequiredPackages Count="6">
    7171      <Item1>
     72        <PackageName Value="CoolWeb"/>
     73        <DefaultFilename Value="Packages/CoolWeb/CoolWeb.lpk" Prefer="True"/>
     74      </Item1>
     75      <Item2>
    7276        <PackageName Value="TemplateGenerics"/>
    7377        <DefaultFilename Value="Packages/TemplateGenerics/TemplateGenerics.lpk" Prefer="True"/>
    74       </Item1>
    75       <Item2>
     78      </Item2>
     79      <Item3>
    7680        <PackageName Value="CoolTranslator"/>
    7781        <DefaultFilename Value="Packages/CoolTranslator/CoolTranslator.lpk" Prefer="True"/>
    78       </Item2>
    79       <Item3>
    80         <PackageName Value="FCL"/>
    8182      </Item3>
    8283      <Item4>
     84        <PackageName Value="FCL"/>
     85      </Item4>
     86      <Item5>
    8387        <PackageName Value="Common"/>
    8488        <DefaultFilename Value="Packages/Common/Common.lpk" Prefer="True"/>
    85       </Item4>
    86       <Item5>
     89      </Item5>
     90      <Item6>
    8791        <PackageName Value="LCL"/>
    88       </Item5>
     92      </Item6>
    8993    </RequiredPackages>
    9094    <Units Count="17">
     
    215219    <SearchPaths>
    216220      <IncludeFiles Value="$(ProjOutDir)"/>
    217       <OtherUnitFiles Value="Forms;DbEngines"/>
     221      <OtherUnitFiles Value="Forms;DbEngines;/usr/lib/mysql/;/usr/lib64/mysql/"/>
    218222      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    219223    </SearchPaths>
  • trunk/MyData.lpr

    r10 r12  
    1010  Forms, UFormTables, UDatabase, UCore, Common, CoolTranslator, UEngineXML,
    1111  UFormTable, UFormRecords, UFormRecord, UFormFields, UFormField, UDataTypes,
    12   TemplateGenerics, UEngineMySQL, UEngineSQLite, UFormMain, UFormConnect,
    13   UFormDatabases, UFormPreferences;
     12  TemplateGenerics, CoolWeb, UEngineMySQL, UEngineSQLite, UFormMain,
     13  UFormConnect, UFormDatabases, UFormPreferences;
    1414
    1515{$R *.res}
  • trunk/UDatabase.pas

    r9 r12  
    156156  TDatabaseClient = class
    157157    Database: TDatabase;
     158    constructor Create; virtual;
    158159    procedure Load; virtual;
    159160    procedure Save; virtual;
     
    206207
    207208{ TDatabaseClient }
     209
     210constructor TDatabaseClient.Create;
     211begin
     212end;
    208213
    209214procedure TDatabaseClient.Load;
Note: See TracChangeset for help on using the changeset viewer.