我正在创建一个事务,我想在一个表中更新用户并删除属于该用户的另一个数据。但只执行第一个查询,而不执行第二个查询。在第二个查询中的delete语句code
是逗号分隔的std :: string。
pqxx::connection c(connectionString);
try {
pqxx::work w(c);
pqxx::result r;
c.prepare("user", "update user set started = null, finished = null, task = $1 where id = $2");
r = w.prepared("user")(task)(email).exec();
c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code in ($1) and id = $2)");
r = w.prepared("belongings")(code)(id).exec();
w.commit();
}
我读了this SO-thread,解释了如何在commit()之前运行多个查询。所以我必须在第二个删除语句中犯错,但无法找到原因。
答案 0 :(得分:1)
code
参数被解释为单个文字。您可以尝试使用any(array expression),
的替代语法,例如:
code = "{abc,def}"; // instead of code = "'abc','def'"
...
c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code = any ($1) and id = $2)");
r = w.prepared("belongings")(code)(id).exec();