Query Execution and Processing Functions

Once a connection has been established to the database backend, you can use the following functions to send queries to the database and process returned result sets.

doquery()

doquery sends a command or query to the database backend using the current connection and waits for the result.

PGresult* doquery (char *query);

This routine submits a command or query to the database backend and waits for the result. The routine returns a PGresult pointer or possibly a NULL pointer. The PGresult pointer returned by doquery can be used by libpq functions as well. doquery encapsulates the PQexec libpq function and performs error handling on the PQexec call and resultant PGresult object.

fetch()

fetch retrieves data from a binary cursor.

int fetch (void *param, ...);

This routine enables you to pass pointers as parameters and, on return, the variables are filled with data from a binary cursor. In general, these cursors cannot be used if you are running the pgeasy client on a system with a different architecture than that of the database server. If you pass a NULL pointer as a parameter, the corresponding column is skipped. fetch returns the tuple number (starting at 0) or END_OF_TUPLES if at the end of the cursor's data.

fetchwithnulls()

fetchwithnulls retrieves data from the binary cursor and indicates the NULL status of the field in an integer variable provided after each result pointer.

int fetchwithnulls (void *param, ...);

This routine is similar to fetch but also provides a NULL indicator in the argument directly following the result pointer. The variable pointed to by the argument can be 0 (non-NULL) or 1 (NULL). The NULL indicator must be passed in as an int*. fetchwithnulls returns the tuple number (starting at 0) or END_OF_TUPLES if at the end of the cursor's data.

reset_fetch()

reset_fetch forces the fetch index back to the beginning.

void reset_fetch ();

This routine sets the tuple back to 0 (which, in effect, resets fetch index to the beginning).

get_result()

get_result returns the current internal result set.

PGresult* get_result ();

This routine returns the current internal result set. This function, used in conjunction with set_result and unset_result, allows the user to handle multiple result sets at the same time.

set_result()

set_result sets the current internal result set.

void set_result (PGresult* new_result);

This routine sets the current internal result set to the result set indicated by new_result, which must have been previously obtained with a get_result.

unset_result()

unset_result unsets the last PGresult set by set_result.

void unset_result (PGresult* old_result);

This routine unsets the last PGresult set using the set_result call. Calling unset_result before set_result causes an error.