aboutsummaryrefslogtreecommitdiff
path: root/sandbox/pgsql/pgsql.c
blob: ffbae9f289aff2c63fe4192b6d3349b050ca5db1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>

#include <libpq-fe.h>
#include <pg_config.h>

int main() {
	PGconn* conn;
	PGresult* result;

	conn = PQconnectdb("host=localhost port=5432 dbname=clog password=p0stgres user=postgres");

	if(PQstatus(conn) != CONNECTION_OK) {
		printf("Connection to database failed:%s\n", PQerrorMessage(conn));
	}

	result = PQexec(conn, "SELECT * FROM ENTRIES");

	PQprintOpt options = {0};
	options.header = 1;    /* Ask for column headers */
	options.align = 1;    /* Pad short columns for alignment */
	options.fieldSep = "|";  /* Use a pipe as the field separator */

	PQprint(stdout, result, &options);

	PQclear(result);
	PQfinish(conn);
}