koshachok koshachok - 1 year ago 156
C++ Question

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). 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)

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

I have no idea how to rewrite it using pqxx. I've rewrite some piece of code in pqxx, u can see it here.
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. And if u left some links with big pqxx-examples, it would be great.

Answer Source

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.

The analogue Postgres code would be

vector<tuple<string, string, string>> result_set;
pqxx::work txn(*conn);
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download