以下是我的代码:
std::unique_ptr<pqxx::connection> conn = connect();
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
try{
conn->prepare("add_pr_file", "select * from add_pr_file($1, $2, $3)");
conn->prepare("entire_add_pr", " select * from entire_add_pr($1, $2, $3, $4, $5)");
pqxx::work tr(*conn.get(), "add_pr");
pqxx::binarystring data((pr.input_data.empty() ? nullptr : (const void *)pr.input_data.data()), pr.input_data.size());
tr.prepared("entire_add_pr")(pr.guid.to_str())(conv.to_bytes(pr.name))(data)(std::to_string(pr.rate))(conv.to_bytes(pr.type));
for (auto file : pr.files) {
tr.prepared("add_pr_file")(pr.guid.to_str())(conv.to_bytes(file.path))(type_cnv::type(file.module)).exec();
}
tr.commit();
}
catch (const pqxx::pqxx_exception &exc) {
THROW(exc.base().what());
}我无法执行entire_add_pr函数。此函数必须在表pr中添加一行。未发生异常,但在commit结果中,pr表中没有行。但是,add_pr_file语句在commit之后获得结果。这是entire_add_pr函数:
create or replace function entire_add_pr( _guid uuid, _name character varying, _input_data bytea, _rate integer, _type_name character varying )
returns void as $$
begin
insert into pr (guid, name, input_data, rate_priority, pr_type_id) values (_guid, _name, _input_data, _rate, (select id from pr_type where type_name = _type_name));
end;
$$
language plpgsql;如果我从postgresql命令行执行查询,则该函数运行良好:
select * from entire_add_pr('1aaa9aaa-aaaa-aaaa-aaaa-aaaaaaaaa111', 'pr_name', '123', 10, 'test type');发布于 2016-01-14 21:54:09
我忘了执行exec方法:
tr.prepared("entire_add_pr")(pr.guid.to_str())(conv.to_bytes(pr.name))(data)(std::to_string(pr.rate))(conv.to_bytes(pr.type)).exec();https://stackoverflow.com/questions/34789931
复制相似问题