Sign in Join
Wiki copytemporary

TSQLExporter/ja

English · 日本語

TSQLExporter は、TDataSet で使用するデータベース エクスポート コンポーネントである。 lazdbexport パッケージをインストールすると、 Component Palette/jaの [Data Export] タブに表示される。 TDataSet の内容 (たとえば、TSQLConnector/ja および TSQLTransaction/ja とリンクするように正しく設定された TSQLQuery/ja の結果) をエクスポートするには、FormatSettings.TableName も提供する必要がある。

以下の例では、TSynEdit にテーブル 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;                 // エクスポーターは挿入ステートメントでテーブル名を使用する
      DateFormat :=     'YYYY-MM-DD';           // SQL 日付フォーマット
      DateTimeFormat := 'YYYY-MM-DD hh:mm:ss';  // 
    end;

    myExporter.ExportToStream( ts );
    myScriptText.Text := ts.DataString;  // 形式がついたスクリプトテキストを表示

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

From the Free Pascal wiki, page "TSQLExporter/ja", as it stood on 2024-03-31 after a change by Ariben, 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 1 person, 2024

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
AribenCreated page
Ariben

Talk about this page

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