Delphi : Select 使用参数进入输出文件

Delphi : Select into outfile using parameter

我正在尝试使用 MySQL:

在 Delphi 中使用 Select Into Outfile 命令
dirfile:=pathProg+SaveDialog1.FileName+'.csv';

With dm.Query
do 
    begin
    SQL.Clear;
    SQL.Text:='SELECT * FROM tabel1  INTO OUTFILE :parfile';
    Parameters.ParamByName('parfile').value:=dirfile;
    ExecSQL;
    end;

但它不起作用,它 returns 一个错误:

you have error in your sql syntax check the manual that corresponds to your mariadb server version for the right syntakx to use near

有解决这个问题的建议吗?

四处搜索后,发现您不能为文件名使用参数化值,它必须是字符串文字。在这种情况下,您将不得不手动构建 SQL 字符串,例如:

dirfile:=pathProg+SaveDialog1.FileName+'.csv';

with dm.Query do 
begin
  SQL.Text := 'SELECT * FROM tabel1 INTO OUTFILE ' + QuotedStr(dirfile);
  ExecSQL;
end;