How to configure proper PostgreSQL results in Linux?
I am migrating from MySQL to PostgreSQL. With Postgres I can make a connection, which is perfect. After this, every query results a NULL pointer. What can be wrong?
I use Linuxmint 16, with Postgres 9.1 and libpq in eclipse C++ 4.7
m_connection = PQconnectStart ( dbname=restaurant user=mensfort password=zhongguo hostaddr=127.0.0.1 port=5432 ) connected = PQstatus( m_connection); /* => result is CONNECTION_STARTED */ PGresult *res = PQexec( m_connection, "BEGIN"); /* -> Always a NULL pointer. */ ExecStatusType status = PQresultStatus(res);
I'm sure the database is available and the user exists with a proper password.
According to a friend, I changed the authentication: Make changes to pg_hba.conf (authetification methods).
host all all 127.0.0.1/32 trust # md5 -> trust
What else can I configure to make Postgres work on a local PC?
I strongly recommend reading the documentation - start with the libpq example program here.
You'll notice that it tests PQresultStatus(res) != PGRES_COMMAND_OK and if it's false, calls PQerrorMessage(conn) to get the error info.
You should never be caring what res's value is. It's an opaque value to your program. In this case PostgreSQL is returning NULL to indicate an error, but you're supposed to use PQresultStatus(res) to check that, not test it directly. To get the error you query the connection object.