db_postgres: Refactor open() behavior to be consistent with other DBs (#6381)

This commit is contained in:
Lyndsy Simon 2017-09-15 10:56:08 -04:00 • committed by Andreas Rumpf
commit 8ea78b1bc9

View file

@ -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 ## See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
## for more information. ## for more information.
## let
## Note that the connection parameter is not used but exists to maintain colonPos = connection.find(':')
## the nim db api. host = if colonPos < 0: connection
result = pqsetdbLogin(nil, nil, nil, nil, database, user, password) 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 if pqStatus(result) != CONNECTION_OK: dbError(result) # result = nil
proc setEncoding*(connection: DbConn, encoding: string): bool {. proc setEncoding*(connection: DbConn, encoding: string): bool {.