diff options
author | Lyndsy Simon <lyndsy@lyndsysimon.com> | 2017-09-15 10:56:08 -0400 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-09-15 16:56:08 +0200 |
commit | 8ea78b1bc9dc0b4d883b4f0750ee84e93605b82a (patch) | |
tree | 1578878a825079c1b9412f7e7ff811e5b1ab99bf /lib | |
parent | 88a5e9d88ccc0a48daa2710e88d2efb8a7ae6468 (diff) | |
download | Nim-8ea78b1bc9dc0b4d883b4f0750ee84e93605b82a.tar.gz |
db_postgres: Refactor open() behavior to be consistent with other DBs (#6381)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/impure/db_postgres.nim | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index fc587b5df..a42950557 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -516,10 +516,13 @@ proc open*(connection, user, password, database: string): DbConn {. ## ## See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING ## for more information. - ## - ## Note that the connection parameter is not used but exists to maintain - ## the nim db api. - result = pqsetdbLogin(nil, nil, nil, nil, database, user, password) + let + colonPos = connection.find(':') + host = if colonPos < 0: connection + else: substr(connection, 0, colonPos-1) + port = if colonPos < 0: "" + else: substr(connection, colonPos+1) + result = pqsetdbLogin(host, port, nil, nil, database, user, password) if pqStatus(result) != CONNECTION_OK: dbError(result) # result = nil proc setEncoding*(connection: DbConn, encoding: string): bool {. |