Ignore:
Timestamp:
Mar 23, 2018, 3:06:47 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Allow to create and remove tables for XML backend.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DbEngines/UEngineXML.pas

    r20 r21  
    3030    procedure LoadFromFile(FileName: string);
    3131    procedure SaveToFile(FileName: string);
    32     function GetNextPart(var Text: string): string;
     32    function GetNextPart(var Text: string; Separator: string = ' '): string;
    3333  protected
    3434  public
    35     procedure Query(DbRows: TDbRows; Text: string); override;
     35    procedure Query(Text: string; DbRows: TDbRows = nil); override;
    3636    procedure LoadTables(Tables: TTables); override;
    3737    procedure Load; override;
     
    158158begin
    159159  Field.Name := ReadString(Node, 'Name', '');
    160   Field.DataType := Field.Table.DbClient.ClientType.DataTypes.FindByType(TFieldType(ReadInteger(Node, 'Type', 0)));
     160  Field.DataType := Field.Table.DbClient.ClientType.DataTypes.SearchByType(TFieldType(ReadInteger(Node, 'Type', 0)));
    161161  Field.TextBefore := ReadString(Node, 'TextBefore', '');
    162162  Field.TextAfter := ReadString(Node, 'TextAfter', '');
     
    296296      SaveNodeTables(Tables, NewNode);
    297297    end;
    298     ForceDirectories(ExtractFileDir(FileName));
     298    if Pos(DirectorySeparator, FileName) > 0 then
     299      ForceDirectories(ExtractFileDir(FileName));
    299300    WriteXMLFile(Doc, FileName);
    300301  finally
     
    303304end;
    304305
    305 function TDatabaseXML.GetNextPart(var Text: string): string;
    306 begin
    307   if Pos(' ', Text) > 0 then begin
    308     Result := Trim(Copy(Text, 1, Pos(' ', Text) - 1));
    309     Delete(Text, 1, Pos(' ', Text));
     306function TDatabaseXML.GetNextPart(var Text: string; Separator: string = ' '): string;
     307begin
     308  if Pos(Separator, Text) > 0 then begin
     309    Result := Trim(Copy(Text, 1, Pos(Separator, Text) - Length(Separator)));
     310    Delete(Text, 1, Pos(Separator, Text));
    310311  end else begin
    311312    Result := Text;
     
    314315end;
    315316
    316 procedure TDatabaseXML.Query(DbRows: TDbRows; Text: string);
     317procedure TDatabaseXML.Query(Text: string; DbRows: TDbRows = nil);
    317318var
    318319  Command: string;
     
    348349      end else raise Exception.Create('Unsupported columns ' + Columns + ' specification');
    349350    end else raise Exception.Create('Table ' + TableName + ' not found.');
    350   end else raise Exception.Create('Unsupported SQL command ' + Command);
     351  end else
     352  if Command = 'CREATE' then begin
     353    Command := GetNextPart(Text);
     354    if Command = 'TABLE' then begin
     355      TableName := GetNextPart(Text);
     356      Table := TTable.Create;
     357      Table.Name := TableName;
     358      Table.DbClient := Self;
     359      Tables.Add(Table);;
     360    end else raise Exception.Create('TABLE keyword expected');
     361  end else
     362  if Command = 'DROP' then begin
     363    Command := GetNextPart(Text);
     364    if Command = 'TABLE' then begin
     365      TableName := GetNextPart(Text);
     366      Table := Tables.SearchByName(TableName);
     367      if Assigned(Table) then Tables.Remove(Table)
     368      else raise Exception.Create('Table ' + TableName + ' not found');
     369    end else raise Exception.Create('TABLE keyword expected');
     370  end else
     371    raise Exception.Create('Unsupported SQL command ' + Command);
    351372end;
    352373
    353374procedure TDatabaseXML.LoadTables(Tables: TTables);
    354375begin
    355   inherited;
    356 
     376  Tables.Assign(Self.Tables);
    357377end;
    358378
    359379procedure TDatabaseXML.Load;
    360380begin
     381  FileName := TDbConnectParamsXml(ConnectProfile.Params).FileName;
    361382  if FileExists(FileName) then
    362383    LoadFromFile(FileName);
Note: See TracChangeset for help on using the changeset viewer.