TSQLExporter

From Lazarus wiki
Revision as of 12:04, 5 September 2016 by Arent (talk | contribs) (Created page with "'''TSQLExporter''' image:tsqlexporter.png is a database export component for use with a TDataSet. To export the contents of a TDataSet (for instance the result of a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

TSQLExporter tsqlexporter.png is a database export component for use with a TDataSet.

To export the contents of a TDataSet (for instance the result of a TSQLQuery correctly setup to link with a TSQLConnector and TSQLTransaction) also FormatSettings.TableName need be provided.

In the example below a a TSynEdit is filled with exported contents of table mytable.

type
  myForm = class(TForm)
    btnExport: TButton;
    myDataSource: TDataSource;
    myConnector: TSQLConnector;
    myExporter: TSQLExporter;
    myQuery: TSQLQuery;
    myTransaction: TSQLTransaction;
    myScriptText: TSynEdit;
    mySyntax: TSynSQLSyn;
    procedure btnExportClick(Sender: TObject);
  private
    procedure ExportTable( const tblnam: String );
  end;

implementation


procedure myForm.btnExportClick(Sender: TObject);
begin
  ExportTable( 'mytable' );
end;


procedure myForm1.ExportTable( const tblnam: string );
var
  ts: TStringStream;
begin
  try
    ts := TStringStream.Create( '' );
    myQuery.SQL.Text := 'SELECT * FROM ' + tblnam;
    myQuery.Open();
    myExporter.FormatSettings.TableName := tblnam;
    myExporter.ExportToStream( ts );
    myScriptText.Text := ts.DataString;
    myQuery.Close();
  finally
    ts.Free();
  end;
end;