Connect to PSQL database.
This commit is contained in:
parent
b36749db03
commit
dd8323939e
1 changed files with 16 additions and 0 deletions
16
exporter.c
16
exporter.c
|
@ -12,5 +12,21 @@ int main(int argc, char **argv) {
|
||||||
exit(EXIT_FAILURE);
|
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;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue