首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >postgresql libpqxx -事务后无结果

postgresql libpqxx -事务后无结果
EN

Stack Overflow用户
提问于 2016-01-14 20:42:38
回答 1查看 350关注 0票数 0

以下是我的代码:

代码语言:javascript
复制
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函数:

代码语言:javascript
复制
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命令行执行查询,则该函数运行良好:

代码语言:javascript
复制
select * from entire_add_pr('1aaa9aaa-aaaa-aaaa-aaaa-aaaaaaaaa111', 'pr_name', '123', 10, 'test type');
EN

回答 1

Stack Overflow用户

发布于 2016-01-14 21:54:09

我忘了执行exec方法:

代码语言:javascript
复制
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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34789931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档