在带有返回值的执行块中执行时,不会持久插入

时间:2017-12-18 21:25:18

标签: php pdo firebird

我尝试使用execute block returns (id integer) as begin insert into test (name) values ('test1') returning id into :id; suspend; insert into test (name) values ('test2') returning id into :id; suspend; end; 将两个值插入到我的数据库中,然后返回插入id。

fetch|fetchAll

如果我不调用fetchAll方法,则插入内容不会保留在数据库中。

在执行多次读取结果集的查询后,我无法调用{{1}}。 但是,如果我在那里调用,插入是持久的,我可以获得返回值。

1 个答案:

答案 0 :(得分:0)

您必须获取执行块生成的所有行,以便执行这些语句。 execute block是匿名'存储'程序和suspend语句使其“可选”。

执行时,Firebird会完成suspend语句的工作,等待客户端提取该行,然后继续执行下一个语句,直到它遇到另一个suspend语句。

如果客户端未提取行并且语句已关闭/释放,则Firebird将回滚所有更改,直到上一个suspend(或存储过程的开始/ execute block,如果有以前没有暂停)。

换句话说,execute block需要检索行才能产生持久效果。

否则,单独执行插入可能更好,而不是使用execute block

相关问题