Ignore:
Timestamp:
Mar 23, 2018, 1:59:25 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Database classes reorganized. Now TDbConnectProfile is class which holds information about connection to database.
  • Modified: TDbManager is top most class for managing other database classes.
  • Modified: TDbConnectParams class contains client specific parameters for connect profile.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DbEngines/UEngineMySQL.pas

    r15 r20  
    1212  { TDatabaseMySQL }
    1313
    14   TDatabaseMySQL = class(TDatabaseClient)
     14  TDatabaseMySQL = class(TDbClient)
    1515  private
    1616    procedure LoadFields(Table: TTable);
    17     procedure LoadTables;
     17  protected
     18    procedure LoadTables(Tables: TTables); override;
    1819  public
    1920    SqlDatabase: TSqlDatabase;
     
    2526  end;
    2627
     28  { TDbConnectParamsMySQL }
     29
     30  TDbConnectParamsMySQL = class(TDbConnectParams)
     31  protected
     32    function GetConnectionString: string; override;
     33    procedure SetConnectionString(AValue: string); override;
     34  public
     35    Host: string;
     36    Port: Word;
     37  end;
     38
     39
    2740implementation
     41
     42{ TDbConnectParamsMySQL }
     43
     44function TDbConnectParamsMySQL.GetConnectionString: string;
     45begin
     46  Result := 'mysql://' + Host + ':' + IntToStr(Port);
     47end;
     48
     49procedure TDbConnectParamsMySQL.SetConnectionString(AValue: string);
     50var
     51  URL: TURL;
     52begin
     53  URL := TURL.Create;
     54  try
     55    URL.AsString := AValue;
     56    if (URL.Scheme <> 'mysql') and (AValue <> '') then
     57      raise Exception.Create('Wrong connection string. Required mysql scheme.');
     58    Host := URL.Host.AsString;
     59    Port := URL.Port;
     60  finally
     61    URL.Free;
     62  end;
     63end;
    2864
    2965{ TDatabaseMySQL }
     
    5187      if DbRows2.Count > 0 then begin
    5288        TypeName := TDictionaryStringString(DbRows2[0]).Values['Name'];
    53         NewField.DataType := Table.Database.Engine.DataTypes.FindByName(TypeName);
     89        NewField.DataType := Table.DbClient.ClientType.DataTypes.FindByName(TypeName);
    5490        if not Assigned(NewField.DataType) then
    55           NewField.DataType := Table.Database.Engine.DataTypes.FindByType(ftString);
     91          NewField.DataType := Table.DbClient.ClientType.DataTypes.FindByType(ftString);
    5692      end else begin
    5793        // Use string as default
    58         NewField.DataType := Table.Database.Engine.DataTypes.FindByType(ftString);
     94        NewField.DataType := Table.DbClient.ClientType.DataTypes.FindByType(ftString);
    5995      end;
    6096      Table.Fields.Add(NewField);
     
    66102end;
    67103
    68 procedure TDatabaseMySQL.LoadTables;
     104procedure TDatabaseMySQL.LoadTables(Tables: TTables);
    69105var
    70106  DbRows: TDbRows;
     
    78114      NewTable := TTable.Create;
    79115      NewTable.Id := StrToInt(TDictionaryStringString(DbRows[I]).Values['Id']);
    80       NewTable.Database := Database;
     116      NewTable.DbClient := Self;
    81117      NewTable.Name := TDictionaryStringString(DbRows[I]).Values['Name'];
    82118      NewTable.Caption := TDictionaryStringString(DbRows[I]).Values['Title'];
    83119      LoadFields(NewTable);
    84       Database.Tables.Add(NewTable);
     120      Tables.Add(NewTable);
    85121    end;
    86122  finally
     
    112148  URL := TURL.Create;
    113149  try
    114     URL.AsString := Database.ConnectionString;
     150    URL.AsString := ConnectProfile.Params.ConnectionString;
    115151    if URL.Scheme <> 'mysql' then
    116152      raise Exception.Create('Wrong connection string. Required mysql protocol.');
     
    124160      SqlDatabase.Database := Copy(URL.Path, 2, High(Integer));
    125161    SqlDatabase.Connect;
    126     LoadTables;
    127162  finally
    128163    URL.Free;
Note: See TracChangeset for help on using the changeset viewer.