Autore: Fabio Di Matteo
Ultima revisione: 24/02/2018 - 12:21
#include <iostream> #include <pqxx/pqxx> int main(int, char *argv[]) { try { pqxx::connection c{"user=fabio password=fabio dbname=test hostaddr=192.168.1.4 port=5432"}; pqxx::work txn{c}; pqxx::result r = txn.exec("SELECT * from persone;"); for (auto row: r) std::cout << row["id"].c_str() <<" "<< row["nome"].c_str() <<" "<< row["cognome"].c_str() <<" "<< row["email"].c_str() << std::endl; txn.commit(); } catch (const pqxx::sql_error &e) { std::cerr << "SQL error: " << e.what() << std::endl; std::cerr << "Query was: " << e.query() << std::endl; } catch (const std::exception &e) { std::cerr << "Error: " << e.what() << std::endl; } }
#include <iostream> #include <pqxx/pqxx> int main(int, char *argv[]) { try { pqxx::connection c{"user=fabio password=fabio dbname=test hostaddr=192.168.1.4 port=5432"}; pqxx::work txn{c}; pqxx::result r = txn.exec("insert into persone (nome,cognome,email) values ('C++', 'Libpqxx','libpqxx@local.com');"); txn.commit(); } catch (const pqxx::sql_error &e) { std::cerr << "SQL error: " << e.what() << std::endl; std::cerr << "Query was: " << e.query() << std::endl; } catch (const std::exception &e) { std::cerr << "Error: " << e.what() << std::endl; } }
all: g++ main.cpp `pkg-config --libs --cflags libpqxx` -o pq
Il nostro wiki installa solamente cookie tecnici necessari al funzionamento della piattaforma "Dokuwiki". Niente analitics, statistiche, tracciamenti o altro.