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?

Answers


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.


Need Your Help

setUserCredentials from Google data api is stuck

authentication google-calendar-api

Well, since I am facing some issues with OAuth implementation, I decided to go back to normal method where users will input their login id and password and I will use them in my code to validate th...

bootstrap3 make menu collapse sooner

css twitter-bootstrap navbar

I've seen similar questions but not the one that will help me..