July 2005
Intermediate to advanced
1032 pages
27h 10m
English
Now let's turn our attention to the task of processing a query. I'll start by showing a simple example—you'll connect to a database, execute a hard-wired query, process the results, clean up, and exit.
1 /* 2 ** File: client3.c 3 */ 4 5 #include <stdlib.h> 6 #include <libpq-fe.h> 7 8 void process_query( PGconn * connection, const char * query_text ) 9 { 10 PGresult * result; 11 PQprintOpt options = {0}; 12 13 if(( result = PQexec( connection, query_text )) == NULL ) 14 { 15 printf( "%s\n", PQerrorMessage( connection )); 16 return; 17 } 18 19 options.header = 1; /* Ask for column headers */ 20 options.align = 1; /* Pad short columns for alignment */ 21 options.fieldSep = "|"; /* Use a pipe as ...Read now
Unlock full access