From 40441e01b6e73a0a1d7f06377b3607f151aed65b Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Thu, 23 Sep 2021 00:22:10 -0500 Subject: Add pgsql sandbox --- sandbox/pgsql/pgsql.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sandbox/pgsql/pgsql.c (limited to 'sandbox/pgsql/pgsql.c') diff --git a/sandbox/pgsql/pgsql.c b/sandbox/pgsql/pgsql.c new file mode 100644 index 0000000..ffbae9f --- /dev/null +++ b/sandbox/pgsql/pgsql.c @@ -0,0 +1,28 @@ +#include + +#include +#include + +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); +} + -- cgit v1.2.3