Ignore:
Timestamp:
Mar 23, 2018, 1:59:25 PM (7 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/UEngineXML.pas

    r17 r20  
    1212  { TDatabaseXML }
    1313
    14   TDatabaseXML = class(TDatabaseClient)
     14  TDatabaseXML = class(TDbClient)
    1515  private
    16     function GetFileName: string;
     16    FFileName: string;
     17    Tables: TTables;
    1718    procedure LoadNodeRecord(Row: TRecord; Node: TDOMNode);
    1819    procedure SaveNodeRecord(Row: TRecord; Node: TDOMNode);
     
    3031    procedure SaveToFile(FileName: string);
    3132    function GetNextPart(var Text: string): string;
     33  protected
    3234  public
    3335    procedure Query(DbRows: TDbRows; Text: string); override;
     36    procedure LoadTables(Tables: TTables); override;
    3437    procedure Load; override;
    3538    procedure Save; override;
    36     property FileName: string read GetFileName;
     39    constructor Create; override;
     40    destructor Destroy; override;
     41    property FileName: string read FFileName write FFileName;
     42  end;
     43
     44  { TDbConnectParamsXml }
     45
     46  TDbConnectParamsXml = class(TDbConnectParams)
     47  protected
     48    function GetConnectionString: string; override;
     49    procedure SetConnectionString(AValue: string); override;
     50  public
     51    FileName: string;
    3752  end;
    3853
     
    4661  SWrongFileFormat = 'Wrong file format';
    4762
    48 { TDatabaseXML }
    49 
    50 function TDatabaseXML.GetFileName: string;
     63{ TDbConnectParamsXml }
     64
     65function TDbConnectParamsXml.GetConnectionString: string;
     66begin
     67  Result := 'file:///' + FileName;
     68end;
     69
     70procedure TDbConnectParamsXml.SetConnectionString(AValue: string);
    5171var
    5272  URL: TURL;
     
    5474  URL := TURL.Create;
    5575  try
    56     URL.AsString := Database.ConnectionString;
    57     if URL.Scheme <> 'file' then
     76    URL.AsString := AValue;
     77    if (URL.Scheme <> 'file') and (AValue <> '') then
    5878      raise Exception.Create('Wrong connection string. Required file scheme.');
    59 
    60     Result := URL.Path
     79    FileName := Copy(URL.Path, 2, Length(URL.Path));
    6180  finally
    6281    URL.Free;
    6382  end;
    6483end;
     84
     85{ TDatabaseXML }
    6586
    6687procedure TDatabaseXML.LoadNodeRecord(Row: TRecord; Node: TDOMNode);
     
    137158begin
    138159  Field.Name := ReadString(Node, 'Name', '');
    139   Field.DataType := Field.Table.Database.Engine.DataTypes.FindByType(TFieldType(ReadInteger(Node, 'Type', 0)));
     160  Field.DataType := Field.Table.DbClient.ClientType.DataTypes.FindByType(TFieldType(ReadInteger(Node, 'Type', 0)));
    140161  Field.TextBefore := ReadString(Node, 'TextBefore', '');
    141162  Field.TextAfter := ReadString(Node, 'TextAfter', '');
     
    219240  while Assigned(Node2) and (Node2.NodeName = 'Table') do begin
    220241    NewTable := TTable.Create;
    221     NewTable.Database := Tables.Database;
     242    NewTable.DbClient := Tables.DbClient;
    222243    LoadNodeTable(NewTable, Node2);
    223244    Tables.Add(NewTable);
     
    252273      NewNode := FindNode('Tables');
    253274      if Assigned(NewNode) then
    254         LoadNodeTables(Database.Tables, NewNode);
     275        LoadNodeTables(Tables, NewNode);
    255276    end;
    256277  finally
     
    273294      NewNode := OwnerDocument.CreateElement('Tables');
    274295      AppendChild(NewNode);
    275       SaveNodeTables(Database.Tables, NewNode);
     296      SaveNodeTables(Tables, NewNode);
    276297    end;
    277298    ForceDirectories(ExtractFileDir(FileName));
     
    310331      TableName := GetNextPart(Text);
    311332    end else raise Exception.Create('No table specified with FROM');
    312     Table := Database.Tables.SearchByName(TableName);
     333    Table := Tables.SearchByName(TableName);
    313334    if Assigned(Table) then begin
    314335      DbRows.Count := 0;
     
    330351end;
    331352
     353procedure TDatabaseXML.LoadTables(Tables: TTables);
     354begin
     355  inherited;
     356
     357end;
     358
    332359procedure TDatabaseXML.Load;
    333360begin
     
    341368end;
    342369
     370constructor TDatabaseXML.Create;
     371begin
     372  Tables := TTables.Create;
     373  inherited Create;
     374end;
     375
     376destructor TDatabaseXML.Destroy;
     377begin
     378  Tables.Free;
     379  inherited Destroy;
     380end;
     381
    343382
    344383end.
Note: See TracChangeset for help on using the changeset viewer.