Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get values from array using libpqxx?

How can I get values from array using libpqxx? For Example I have table like this:

CREATE TABLE testTable
(
 testArray integer[]
);

How do I get int array with these values in C++?

like image 853
ktoś tam Avatar asked Aug 11 '26 10:08

ktoś tam


1 Answers

In the version 7.2 I am using the as_array method to parse an array of integers:

list<unsigned long> found_messages;
pqxx::result res = db->execute(query);
auto arr = res[0][0].as_array();
pair<pqxx::array_parser::juncture, string> elem;
do
{
    elem = arr.get_next();
    if (elem.first == pqxx::array_parser::juncture::string_value)
        found_messages.push_back(stoul(elem.second));
}
while (elem.first != pqxx::array_parser::juncture::done);
like image 67
karastojko Avatar answered Aug 12 '26 23:08

karastojko