public inbox for [email protected]help / color / mirror / Atom feed
libpq usage from C++ 3+ messages / 3 participants [nested] [flat]
* libpq usage from C++ @ 2026-03-14 04:40 Igor Korot <[email protected]> 2026-03-14 04:51 ` Re: libpq usage from C++ Adrian Klaver <[email protected]> 2026-03-16 10:25 ` Re: libpq usage from C++ Dominique Devienne <[email protected]> 0 siblings, 2 replies; 3+ messages in thread From: Igor Korot @ 2026-03-14 04:40 UTC (permalink / raw) To: pgsql-generallists.postgresql.org <[email protected]> Hi, ALL, Does anybody use libpq from C++? C++ introduces STL. C++ introduces smart-pointers. Is there a simple way of using those writing libpq communication? Or should I just forget about them and use good old "dump pointers"? Thank you. ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq usage from C++ 2026-03-14 04:40 libpq usage from C++ Igor Korot <[email protected]> @ 2026-03-14 04:51 ` Adrian Klaver <[email protected]> 1 sibling, 0 replies; 3+ messages in thread From: Adrian Klaver @ 2026-03-14 04:51 UTC (permalink / raw) To: Igor Korot <[email protected]>; pgsql-generallists.postgresql.org <[email protected]> On 3/13/26 9:40 PM, Igor Korot wrote: > Hi, ALL, > > Does anybody use libpq from C++? Search engine of choice: libpq c++ yields: https://pqxx.org/development/libpqxx/ > > C++ introduces STL. > C++ introduces smart-pointers. > > Is there a simple way of using those writing libpq communication? > > Or should I just forget about them and use good old "dump pointers"? > > Thank you. > > -- Adrian Klaver [email protected] ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq usage from C++ 2026-03-14 04:40 libpq usage from C++ Igor Korot <[email protected]> @ 2026-03-16 10:25 ` Dominique Devienne <[email protected]> 1 sibling, 0 replies; 3+ messages in thread From: Dominique Devienne @ 2026-03-16 10:25 UTC (permalink / raw) To: Igor Korot <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]> On Sat, Mar 14, 2026 at 5:41 AM Igor Korot <[email protected]> wrote: > Does anybody use libpq from C++? Yes > C++ introduces STL. > C++ introduces smart-pointers. > Is there a simple way of using those writing libpq communication? > Or should I just forget about them and use good old "dump pointers"? Using an existing wrapper is simplest, of course. We wrote our own. To each its own. E.g. PS: Avoid the fwd-decl by using the actual libpq headers instead. extern "C" { struct pg_conn; struct pg_result; typedef struct pg_conn PGconn; typedef struct pg_result PGresult; typedef struct _PQconninfoOption PQconninfoOption; typedef struct pgNotify PGnotify; void PQfreemem(void *ptr); void PQclear(PGresult* res); void PQfinish(PGconn* conn); void PQconninfoFree(PQconninfoOption* conn); } // extern "C" namespace acme::postgresql { struct PGDeleterFunctor { void operator()(PGresult* r) { if (r != nullptr) { PQclear(r); } } void operator()(PGconn* c) { if (c != nullptr) { PQfinish(c); } } void operator()(PQconninfoOption* c) { if (c != nullptr) { PQconninfoFree(c); } } void operator()(PGnotify* n) { if (n != nullptr) { PQfreemem(n); } } }; using PGresult_uptr = std::unique_ptr<PGresult, PGDeleterFunctor>; using PGconn_uptr = std::unique_ptr<PGconn, PGDeleterFunctor>; using PGconninfo_uptr = std::unique_ptr<PQconninfoOption, PGDeleterFunctor>; using PGnotify_uptr = std::unique_ptr<PGnotify, PGDeleterFunctor>; ... } Then we have higher-level wrappers that compose those RAII low-level ones. --DD ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-03-16 10:25 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-03-14 04:40 libpq usage from C++ Igor Korot <[email protected]> 2026-03-14 04:51 ` Adrian Klaver <[email protected]> 2026-03-16 10:25 ` Dominique Devienne <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox