简体   繁体   English

如何从 nodejs 和 node-firebird 执行多个程序?

[英]How to execute multiples procedures from nodejs and node-firebird?

I'm using Firebird 2.5 and node-firebird 0.8.6.我正在使用 Firebird 2.5 和 node-firebird 0.8.6。 I have to run SQL files with multiple stored procedures but I always got errors like the ones below我必须使用多个存储过程运行 SQL 文件,但我总是遇到如下错误

Error: Dynamic SQL Error, SQL error code = -104, Token unknown - line 1, column 5, term at doCallback (/home/somasys/Downloads/testefb/node_modules/node-firebird/lib/index.js:1234:18) at /home/somasys/Downloads/testefb/node_modules/node-firebird/lib/index.js:2929:21 at /home/somasys/Downloads/testefb/node_modules/node-firebird/lib/messages.js:151:25 at search (/home/somasys/Downloads/testefb/node_modules/node-firebird/lib/messages.js:117:13) at /home/somasys/Downloads/testefb/node_modules/node-firebird/lib/messages.js:54:21 at FSReqCallback.wrapper [as oncomplete] (fs.js:477:5)错误:动态 SQL 错误,SQL 错误代码 = -104,令牌未知 - 第 1 行,第 5 列,doCallback 处的术语 (/home/somasys/Downloads/testefb/node_modules/node-firebird/lib/index.js:1234:18 ) 在 /home/somasys/Downloads/testefb/node_modules/node-firebird/lib/index.js:2929:21 在 /home/somasys/Downloads/testefb/node_modules/node-firebird/lib/messages.js:151: 25 在搜索 (/home/somasys/Downloads/testefb/node_modules/node-firebird/lib/messages.js:117:13) at /home/somasys/Downloads/testefb/node_modules/node-firebird/lib/messages.js :54:21 在 FSReqCallback.wrapper [as oncomplete] (fs.js:477:5)

Here it's some parts of my SQL file:这是我的 SQL 文件的一些部分:

set term ^;
CREATE OR ALTER PROCEDURE PRC_CALCULATRIBUTA() 
   BEGIN 
      ...
   END^
set term ;^
commit work;

set term ^;
CREATE OR ALTER PROCEDURE PRC_CORRIGEENCERR() 
   BEGIN 
      ...
   END^
set term ;^
commit work;

I've already tried to remove these set term and commit work and ran it (SQL script) inside a我已经尝试删除这些set termcommit work并在一个内部运行它(SQL 脚本)

EXECUTE BLOCK AS 
BEGIN
  ...
END

but even so I got the same errors like the one described above.但即便如此,我还是遇到了与上述相同的错误。 Is there any instruction or statement to put inside my SQL script?是否有任何指令或语句可以放入我的 SQL 脚本中?

Firebird's statement API can only execute individual statements. Firebird 的语句 API 只能执行单个语句。 In addition, the SET TERM statement is not part of the Firebird SQL syntax.此外, SET TERM语句不是 Firebird SQL 语法的一部分。 It is only a client-side feature in ISQL and other Firebird tools to determine when a statement is done.它只是 ISQL 和其他 Firebird 工具中用于确定语句何时完成的客户端功能。 See also firebird procedural query throwing "token unknown" error at "SET TERM #;"另请参阅firebird 程序查询在“SET TERM #;”处抛出“令牌未知”错误. .

You will need to:您将需要:

  • split up your SQL script in individual statements,将您的 SQL 脚本拆分为单独的语句,
  • remove the SET TERM statements删除SET TERM语句
  • remove any statement terminators outside the procedure bodies, and删除过程体之外的任何语句终止符,以及
  • execute the statements individually.单独执行语句。

I would also suggest to not execute commit work , but instead use the transaction control options from node-firebird.我还建议不要执行commit work ,而是使用 node-firebird 的事务控制选项。 I'm not sure if executing commit work will work in node-firebird, but some drivers will break because you just closed a transaction on them without using their transaction API.我不确定在 node-firebird 中执行commit work是否有效,但是有些驱动程序会中断,因为您只是在没有使用它们的事务 API 的情况下关闭了它们的事务。

In other words, you will need to execute:换句话说,您将需要执行:

CREATE OR ALTER PROCEDURE PRC_CALCULATRIBUTA() 
   BEGIN 
      ...
   END

optionally execute the commit, or commit explicitly using the node-firebird API, and then可选择执行提交,或使用 node-firebird API 显式提交,然后

CREATE OR ALTER PROCEDURE PRC_CORRIGEENCERR() 
   BEGIN 
      ...
   END

etc.等等。

You cannot use execute block for this, because execute block doesn't support execution of DDL.您不能为此使用execute block ,因为execute block不支持 DDL 的执行。 There are workarounds to that limitation (using execute statement ), but it is generally not a good use of execute block .该限制有一些解决方法(使用execute statement ),但它通常不是execute block一个很好的用途。

As an aside, committing between creating stored procedures is unnecessary.顺便说一句,在创建存储过程之间提交是不必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM