Database Reference
In-Depth Information
The third part is where we get the version from the PostgreSQL server, and in the
fourth and last part we disconnect from the server. The sample code is as follows:
/*----------------------------------------------------------------
*
*ecpg_sample.pgc
*Get PostgreSQL version using ECPG *
*IDENTIFICATION
*ecpg_sample.c
*
*----------------------------------------------------------------
*/
#include<stdio.h>
#include<sys/types.h>
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
#include<stdio.h>
/* 1 - Declare variable version, in the declare section */
EXEC SQL BEGIN DECLARE SECTION;
char version [1024];
EXEC SQL END DECLARE SECTION;
int main (int argc, char **argv)
{
/* 2 - Connect to PostgreSQL */
EXEC SQL CONNECT TO postgres AS postgres USER postgres;
/* 3 - Get the PostgreSQL version information */
EXEC SQL SELECT version () INTO :version;
fprintf (stdout, "PostgreSQL Version: %s\n", version);
/* 4 - Disconnect from PostgreSQL */
EXEC SQL DISCONNECT ALL;
return 0;
}
 
Search WWH ::




Custom Search