Sign in Join
Wiki copytemporary

TSQLExporter

English · 日本語

TSQLExporter is a database export component for use with a TDataSet. It may be found on the Data Export tab of the Component Palette once you have installed the lazdbexport package. 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.

pascal
type
  myForm = class(TForm)
    btnExport: TButton;
    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 myForm.ExportTable( const tblnam: string );
var
  ts: TStringStream;
begin
  try
    ts := TStringStream.Create( '' );
    myTransaction.Database := myConnector;
    myQuery.Database := myConnector;
    myExporter.DataSet := myQuery;

    myQuery.SQL.Text := 'SELECT * FROM ' + tblnam;
    myQuery.Open();

    with myExporter.FormatSettings do begin
      TableName :=      tblnam;                 // exporter uses tablename in insert statements
      DateFormat :=     'YYYY-MM-DD';           // SQL date format
      DateTimeFormat := 'YYYY-MM-DD hh:mm:ss';  // 
    end;

    myExporter.ExportToStream( ts );
    myScriptText.Text := ts.DataString;  //show formatted script text

    myQuery.Close();
  finally
    ts.Free();
  end;
end;

From the Free Pascal wiki, page "TSQLExporter", as it stood on 2020-07-18 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 2 people, 2016–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
ArentCreated page
Arent
Arent
Arent
Arent
Arent
TrevFixed syntax highlighting (minor)
TrevNote that the lazdbexport package needs to be installed

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.