Skip to content

Commit

Permalink
Allow db_manager use of connections with no parameters
Browse files Browse the repository at this point in the history
Fixes 'Error: database "" does not exist' message.
Closes bug #9037
  • Loading branch information
Sandro Santilli committed Jun 16, 2014
1 parent acc6271 commit 39b3e5f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ..connector import DBConnector
from ..plugin import ConnectionError, DbError, Table

import os
import psycopg2
import psycopg2.extensions
# use unicode!
Expand All @@ -42,14 +43,11 @@ class PostGisDBConnector(DBConnector):
def __init__(self, uri):
DBConnector.__init__(self, uri)

self.host = uri.host()
self.port = uri.port()
self.dbname = uri.database()
self.user = uri.username()
self.passwd = uri.password()

if self.dbname == '' or self.dbname is None:
self.dbname = self.user
self.host = uri.host() or os.environ.get('PGHOST')
self.port = uri.port() or os.environ.get('PGPORT')
self.user = uri.username() or os.environ.get('PGUSER') or os.environ.get('USER')
self.dbname = uri.database() or os.environ.get('PGDATABASE') or self.user
self.passwd = uri.password() or os.environ.get('PGPASSWORD')

try:
self.connection = psycopg2.connect( self._connectionInfo().encode('utf-8') )
Expand Down

0 comments on commit 39b3e5f

Please sign in to comment.