Connect to PSQL database.

This commit is contained in:
Joachim Desroches 2021-09-27 15:35:20 +02:00
parent b36749db03
commit dd8323939e
No known key found for this signature in database
GPG key ID: 6778C9C29C02D691

View file

@ -12,5 +12,21 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
/* Setup database connection parameters */
char connstring[STRLEN];
sprintf(connstring, "database = %s, user = %s", argv[1], USER);
/* Connect to the database */
PGconn *conn = PQconnectdb(connstring);
if (conn == NULL) {
fprintf(stderr, "Out of memory connecting the PostgreSQL\n.");
exit(EXIT_FAILURE);
} else if (PQstatus(conn) != CONNECTION_OK) {
fprintf(stderr, PQerrorMessage(conn));
PQfinish(conn);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}