libpqxx

Results, such as RETURNING, from uncomitted execs?

笑着哭i 提交于 2019-12-11 11:05:12
问题 With libpqxx, is it possible for one prepared statement that exec s but has not yet been commit ted to store results in a result for use in later prepared statements? If so, how can this be done? Code I've stripped it down for readability, but this is essentially what I'm trying to do: void prepare_write_parent_table(connection_base &c){ try { c.prepare("write_parent_table", "INSERT INTO parent_table (column_1) " "SELECT $1 " "RETURNING id" ) ("character", pqxx::prepare::treat_string); }

How to use libpqxx to receive notifications from the PostgreSQL database?

南笙酒味 提交于 2019-12-08 07:32:45
问题 I'm writing C++ applicatoin which needs to receive notifications for data changes from PostgreSQL through libpqxx library. But it's tutorial doesn't include such use case. The notifications must be received on multiple channels. Also I'm using boost::asio as networking library and for me is preferable if possible to use asio socket classes with asynchronous callbacks for notification events instead of polling of raw BSD style sockets. Can someone provide sample code for this or links to some

pqxx::result::tuple has not been declared (PostgreSQL library for c++)

耗尽温柔 提交于 2019-12-08 03:57:56
问题 I try to compile program, which uses pqxx (PostgreSQL lib for c++). One of my function prototypes, looks like this: bool compare(pqxx::result::tuple row1, pqxx::result::tuple row2); Compiler says for this line: classes.h:64:38: error: 'pqxx::result::tuple' has not been declared bool compare(pqxx::result::tuple row1, pqxx::result::tuple row2); I have no idea, why I get this error. I've included pqxx like this: #include <pqxx/pqxx> I use in other place pqxx::result , and it works. Why I cannot

How to prepare statements and bind parameters in Postgresql for C++

孤街浪徒 提交于 2019-12-07 02:33:59
问题 I'm quite new to C++ and know a little bit about pqxx library. What I want to implement is to prepare statements and bind parameters. In PHP I'm used to doing this in such a nice and concise manner: $s = $db->prepare("SELECT id FROM mytable WHERE id = :id"); $s->bindParam(':id', $id); $s->execute(); or using tokens: $data = array(); $data[] = 1; $data[] = 2; $s = $db->prepare("SELECT id FROM mytable WHERE id = ? or id = ?"); $s->execute($data); I tried to fugure out from pqxx documentation

pqxx::result::tuple has not been declared (PostgreSQL library for c++)

岁酱吖の 提交于 2019-12-06 19:43:27
I try to compile program, which uses pqxx (PostgreSQL lib for c++). One of my function prototypes, looks like this: bool compare(pqxx::result::tuple row1, pqxx::result::tuple row2); Compiler says for this line: classes.h:64:38: error: 'pqxx::result::tuple' has not been declared bool compare(pqxx::result::tuple row1, pqxx::result::tuple row2); I have no idea, why I get this error. I've included pqxx like this: #include <pqxx/pqxx> I use in other place pqxx::result , and it works. Why I cannot delare variable of type pqxx::result::tuple ? Thanks, Mike Looking in the different documentations,

Problem compiling program with pqxx

巧了我就是萌 提交于 2019-12-06 04:12:55
问题 I'm trying to compile a very simple program (sample that does nothing) with pqxx, but cannot do it. Here's the 'program': $ cat xx.cpp #include <pqxx/pqxx> using namespace pqxx; int main() { connection conn("dbname=dout1"); return 0; } The command I used to try to compile in C++: g++ -I /usr/local/include/ -L /usr/local/lib/ -l pqxx -I /opt/postgres_home/include/ -L /opt/postgres_home/lib/ -lpq xx.cpp Message returned: /tmp/cc18wMEy.o: In function `pqxx::connect_direct::connect_direct(std:

How to use pqxx::stateless_cursor class from libpqxx?

我只是一个虾纸丫 提交于 2019-12-05 21:29:03
I'm learning libpqxx, the C++ API to PostgreSQL. I'd like to use the pqxx::stateless_cursor class, but 1) I find the Doxygen output unhelpful in this case, and 2) the pqxx.org website has been down for some time now. Anyone know how to use it? I believe this is how I construct one: pqxx::stateless_cursor <pqxx::cursor_base::read_only, pqxx::cursor_base::owned> cursor( work, "SELECT * FROM mytable", ?, ? ); The last two parms are called cname and hold , but are not documented. And once the cursor is created, how would I go about using it in a for() loop to get each row, one at a time? I do not

Problem compiling program with pqxx

天涯浪子 提交于 2019-12-04 10:08:03
I'm trying to compile a very simple program (sample that does nothing) with pqxx, but cannot do it. Here's the 'program': $ cat xx.cpp #include <pqxx/pqxx> using namespace pqxx; int main() { connection conn("dbname=dout1"); return 0; } The command I used to try to compile in C++: g++ -I /usr/local/include/ -L /usr/local/lib/ -l pqxx -I /opt/postgres_home/include/ -L /opt/postgres_home/lib/ -lpq xx.cpp Message returned: /tmp/cc18wMEy.o: In function `pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': xx.cpp:(.text.

pqxx reuse / reactivate a work transaction

天涯浪子 提交于 2019-12-04 04:23:04
I want to use a pqxx::work for multiples queries AND commitments, while the commit function prevent me from using it again. Here is a simple example : pqxx::connection G_connexion("dbname=basetest user=usertest password=1234"); pqxx::work G_work(G_connexion); int main(int argc, char* argv[]) { G_work.exec("insert into test.table1(nom) VALUES('foo');"); G_work.commit();//until here, no problem G_work.exec("insert into test.table1(nom) VALUES('bar');"); //error, transaction already closed G_work.commit(); } When I try to insert the 'bar' value, after the commit, I get a pqxx::usage_error : Error

Inserting NULL/empty string using libpqxx library

烈酒焚心 提交于 2019-12-02 01:02:59
In the following code snippet, the std::string object with name mac is sometimes an empty string (i.e. "") and I want the prepared statement to treat this variable automatically as null. I wonder how this can be achieved in the below code. In my googling attempts, I happened to find that there is a way to set a flag indicating null value but I could not find a concrete example. Could you please provide an example to achieve this? Thnx. try { mConnection->prepare("insertBulkData", mSqlInsertStmt); pqxx::work xAction(*mConnection); for(uint32_t i = 0; i < tList.size(); i++) { TCoreDTO* tCore =