0

这是我的代码:

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功能。此函数必须在 table 中添加一行pr。没有发生异常,但在提交的结果中,pr表中没有行。但是add_pr_file语句在提交后得到结果。这些是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');
4

1 回答 1

1

我忘了执行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();
于 2016-01-14T13:54:08.877 回答