Connect to PSQL database.

This commit is contained in:
Joachim Desroches 2021-09-27 15:35:20 +02:00
parent b36749db03
commit dd8323939e
Signed by untrusted user who does not match committer: jdesroches
GPG Key ID: 6778C9C29C02D691
1 changed files with 16 additions and 0 deletions

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;
}