简体   繁体   English

在C ++项目中从ibpp转换为pqxx

[英]Conversion from ibpp to pqxx in C++ project

I have a C++ code which uses Firebird (driver ibpp), and I need to make a conversion to PostgreSQL (pqxx is used). 我有一个使用Firebird(驱动程序ibpp)的C ++代码,我需要转换为PostgreSQL(使用pqxx)。 Main file which I need to change is this one . 我需要更改的主要文件是这个 I started, but now I have difficulties. 我开始了,但是现在我遇到了困难。

while (st->Fetch())
{
    st->Get(1, tName);
    st->Get(2, fieldName);
    st->Get(3, fieldType);

    if (tName != tableName)
        continue;

    result.push_back(DbField(fieldName, fieldType, ""));
 } 

I have no idea how to rewrite it using pqxx. 我不知道如何使用pqxx重写它。 I've rewrite some piece of code in pqxx, u can see it here . 我已经在pqxx中重写了一些代码,在这里可以看到它。 So can u help me with this fragment? 那你能帮我这个片段吗?

I've just started working with SQL and it could be great, if someone will explain me how does ibpp code-works. 我刚刚开始使用SQL,如果有人向我解释ibpp代码的工作方式,那可能很棒。 And if u left some links with big pqxx-examples, it would be great. 如果您留下一些带有大型pqxx-examples的链接,那就太好了。

IBPP fragment executes the query sql1 and the given loop goes through the resulting table rows and pushes them all to the result which is probably kind of vector. IBPP片段执行查询sql1 ,给定的循环遍历结果表行并将它们全部推到result ,这可能是一种向量。

The analogue Postgres code would be 类似的Postgres代码为

vector<tuple<string, string, string>> result_set;
pqxx::work txn(*conn);
pqxx::result res = txn.exec("SELECT TRIM(RL.RDB$RELATION_NAME), TRIM(FR.RDB$FIELD_NAME), FS.RDB$FIELD_TYPE ...");
for (unsigned i = 0; i < res.size(); ++i)
{
    string first = res[i][0].as<string>("");
    string second = res[i][1].as<string>("");
    string third = res[i][2].as<string>("");
    result_set.push_back(make_tuple(provider, oper, priority));
}

The query of course should be completed, since it is truncated here. 当然,查询应完成,因为此处已将其截断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM