Questions tagged [libpq]

libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.

libpq is also the underlying engine for several other PostgreSQL application interfaces, including those written for C++, Perl, Python, Tcl and ECPG. So some aspects of libpq's behavior will be important to you if you use one of those packages.

Client programs that use libpq must include the header file libpq-fe.h and must link with the libpq library.

345 questions
2
votes
1 answer

Does PostgreSQL count nested BEGIN and END statements, even though it doesn't support autonomous transactions?

I'm working on some C++ code that makes use of libpq to interact with a PostgreSQL database, and I've started writing some functions, each of which internally starts a transaction, applies several changes to the DB, then ends the transaction. I…
bgoldst
  • 34,190
  • 6
  • 38
  • 64
2
votes
1 answer

How to convert a PGresult to custom data type with libpq (PostgreSQL)

I'm using the libpq library in C to accessing my PostgreSQL database. So, when I do res = PQexec(conn, "SELECT point FROM test_point3d"); I don't know how to convert the PGresult I got to my custom data type. I know I can use the PQgetValue…
mocopera
  • 2,803
  • 3
  • 18
  • 10
2
votes
1 answer

How should I handle an error in libpq for postgresql

I'm creating a few simple helper classes and methods for working with libpq, and am wondering if I receive an error from the database - (e.g. SQL error), how should I handle it? At the moment, each method returns a bool depending on whether the…
user3791372
  • 4,445
  • 6
  • 44
  • 78
2
votes
1 answer

Passing C variables into SQL command

I am a newbie in using libpq and work on a postgresql database. So, far I can insert/update/etc a postgresql database using C program, provided I give the actual values inside the quotes. I want to know how to pass a string/integer variable in the…
user3258515
  • 75
  • 1
  • 6
2
votes
2 answers

How to access a HSTORE column using PostgreSQL C library (libpq)?

I cannot find any documentation regarding HSTORE data access using the C library. Currently I'm considering to just convert the HSTORE columns into arrays in my queries but is there a way to avoid such conversions?
Muton
  • 761
  • 2
  • 7
  • 16
2
votes
2 answers

Cannot connect to postgreSQL server using libpq

I'm a complete novice trying to learn PostgreSQL. I'm trying to connect to my postgres server throught a C program using libpq. Here is the server status: home/planb/postgresql-9.2.4/Project status -o "-p 5555" pg_ctl: server is running (PID:…
kensw
  • 33
  • 1
  • 6
2
votes
1 answer

LNK2005 with libpq as static library

I'm writing an application that links all 3rd party code via static libraries (including tinyxml2, sqlite3, openssl and libpq); everything is working fine beyond whenever I try to link to libpqd.lib - having used the 9.1.9 and 9.2.4 sources - I'm…
ZXcvbnM
  • 611
  • 7
  • 16
2
votes
1 answer

Issue on trying to connect to postgres from C

I'm trying to create a database connection with libpq from C. If I create that connection with PQconnectdb, everything works fine, but if I create it with PQconnectdbParams function, with the same parameters only that stored in a different way (see…
artaxerxe
  • 6,281
  • 21
  • 68
  • 106
2
votes
1 answer

PostgreSQL PQstatus always return CONNECTION_OK

I am trying to check connection status with PostgreSQL server with PQstatus and it always always return CONNECTION_OK even when the cable to the server is unplugged.
2
votes
1 answer

libpq with SSL on VC 2010

I have question compiling libpq on windows (VS2010 32 and 64bit) with SSL support. I downloaded the latest source of postgres and also the OpenSSL Win64 v1.0.1c. I ran nmake in libpq folder: cd postgresql-9.2.2\interfaces\libpq nmake /f win32.mak…
550
  • 1,070
  • 1
  • 13
  • 28
2
votes
2 answers

libpq error message deallocation

Here comes a stupid question. libpq's PQerrorMessage function return a char const* char const* msg = PQerrorMessage(conn); Now since it's const, I don't think I should be deallocating it and I've never seen that done in any examples. But then, when…
Ilia Choly
  • 18,070
  • 14
  • 92
  • 160
2
votes
1 answer

PQunescapeBytea() returns a string like "x0a" for E'\n'::bytea

In PostgreSQL's libpq library (the C API), I'm trying to convert from a bytea field that is returned in text representation, to a raw binary string. For example, for a single newline character, the text representation is "\\x0a" (i.e. the characters…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
2
votes
2 answers

libpq outputs notices into the terminal

I'm writing a library that wraps libpq in C. When I execute a query like DROP SCHEMA IF EXISTS bob, and bob doesn't exist, libpq outputs "NOTICE: schema "bob" does not exist, skipping" into my terminal, but then succeeds. Similarly, if I create a…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
2
votes
2 answers

Input Sanitization with libpq / libpqxx

I'm just getting started implementing some client software for a PostgreSQL database. The queries will allow input parameters that come from an untrusted source. Therefore I need to sanitize my transactions before actually commiting them. As for…
moooeeeep
  • 31,622
  • 22
  • 98
  • 187
2
votes
1 answer

Segmentation Fault in postgreSQL client (libpq)

I'm working on a postgreSQL client application using libpq. gcc compiles it without error. When I run the program, however, this function: void print_column(PGconn *connection) { PGresult *id_list; int row; // process_query() calls…
contrapositive
  • 1,381
  • 2
  • 10
  • 11