Skip to content

Commit

Permalink
Merge pull request #1256 from krallin/postgres-use-port-directive
Browse files Browse the repository at this point in the history
dbd: use port for PostgreSQL connections
  • Loading branch information
ddpbsd authored Sep 20, 2017
2 parents ee43a40 + bbb2b20 commit d8816a5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/os_dbd/db_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,19 @@ int mysql_osdb_query_select(void *db_conn, const char *query)
* Returns NULL on error
*/
void *postgresql_osdb_connect(const char *host, const char *user, const char *pass, const char *db,
__attribute__((unused)) unsigned int port, __attribute__((unused)) const char *sock)
unsigned int port, __attribute__((unused)) const char *sock)
{
PGconn *conn;
char portAsString[6];

if (port > 0) {
snprintf(portAsString, 6, "%u", port);
} else {
snprintf(portAsString, 6, "");
}

conn = PQsetdbLogin(host, portAsString, NULL, NULL, db, user, pass);

conn = PQsetdbLogin(host, NULL, NULL, NULL, db, user, pass);
if (PQstatus(conn) == CONNECTION_BAD) {
merror(DBCONN_ERROR, ARGV0, host, db, PQerrorMessage(conn));
PQfinish(conn);
Expand Down

0 comments on commit d8816a5

Please sign in to comment.