在Firebird中输出带有触发器的CSV文件

在Firebird中输出带有触发器的CSV文件,csv,firebird,firebird2.5,ibexpert,Csv,Firebird,Firebird2.5,Ibexpert,是否可以创建一个触发器,在表2更新后立即从表1中选择字段1输出CSV文件 我试过使用 CREATE OR ALTER trigger test_a0 for Table 2 active after insert or update position 0 AS begin if (updating and new.field1 is not null) then output ('C:\test\test.csv'); select field1 from table1; ou

是否可以创建一个触发器,在表2更新后立即从表1中选择字段1输出CSV文件

我试过使用

CREATE OR ALTER trigger test_a0 for Table 2
active after insert or update position 0
AS
begin

  if (updating and new.field1 is not null) then
  output ('C:\test\test.csv');
  select field1 from table1;
  output;
  commit;

end

不,这是不可能在Firebird 2.5的触发器中输出到CSV文件的。如果要输出到文件,则需要在客户端应用程序中执行此操作,或者使用外部表(技术上是二进制格式,而不是文本格式)。可以使用UDF创建复杂的解决方案


在Firebird 3中,使用UDR(用户定义的例程)可能会有一个更简单的解决方案,但这在很大程度上是未知的领域,因此我不确定是否可以通过这种方式完成。

我想您可以使用IBExpert工具来完成


Interbase Expert是一个独立的工具,它不能从FB触发器内部工作,FB触发器是DB内部进程。如果您要确保所有行的字符预定义长度完全相同,并填充太短的行并剪切太长的行,您可以尝试通过外部表来执行此操作。但是强制内部DB进程依赖于外部条件(比如写入CSV文件)的想法是非常糟糕的。让您的触发器发出事件,并创建一个独立的deamon程序,等待这些事件,然后创建这些CSV文件。
 execute ibeblock
 as
 begin
  txt='';
  for
   select firstname, lastname
   from customer
   into :fn,:ln
   do
   begin
      txt=txt+fn+';'+ln+ibec_crlf();
   end;
   ibec_SaveToFile('C:\txt.csv',txt,__stfOverwrite);
 end