summaryrefslogtreecommitdiff
path: root/bin/sql_db.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@tinyerp.com>2009-11-28 00:11:26 +0100
committerChristophe Simonis <chs@tinyerp.com>2009-11-28 00:11:26 +0100
commit2081fa095961bfa5685b38e17024a77070aceae9 (patch)
tree5357c6348c83f187f2f982158c39bb34f2f866f8 /bin/sql_db.py
parent38488751615e19fc217c78ca451793f52f96d721 (diff)
[FIX] connection pool when database password is provided (thanks to Syleam Crew)
lp bug: https://launchpad.net/bugs/488234 fixed bzr revid: chs@tinyerp.com-20091127231126-lbdmz9i9tm50k8f7
Diffstat (limited to 'bin/sql_db.py')
-rw-r--r--bin/sql_db.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/bin/sql_db.py b/bin/sql_db.py
index 5c288efd817..b36634c5956 100644
--- a/bin/sql_db.py
+++ b/bin/sql_db.py
@@ -235,7 +235,7 @@ class ConnectionPool(object):
result = None
for i, (cnx, used) in enumerate(self._connections):
- if not used and cnx.dsn == dsn:
+ if not used and dsn_are_equals(cnx.dsn, dsn):
self._debug('Existing connection found at index %d' % i)
self._connections.pop(i)
@@ -276,7 +276,7 @@ class ConnectionPool(object):
@locked
def close_all(self, dsn):
for i, (cnx, used) in tools.reverse_enumerate(self._connections):
- if cnx.dsn == dsn:
+ if dsn_are_equals(cnx.dsn, dsn):
cnx.close()
self._connections.pop(i)
@@ -295,6 +295,7 @@ class Connection(object):
def __del__(self):
if self._unique:
+ close_db(self.dbname)
self.__LOCKS[self.dbname].release()
def cursor(self, serialized=False):
@@ -313,6 +314,13 @@ for p in ('host', 'port', 'user', 'password'):
def dsn(db_name):
return '%sdbname=%s' % (_dsn, db_name)
+def dsn_are_equals(first, second):
+ def key(dsn):
+ k = dict(x.split('=', 1) for x in dsn.strip().split())
+ k.pop('password', None) # password is not relevant
+ return k
+ return key(first) == key(second)
+
_Pool = ConnectionPool(int(tools.config['db_maxconn']))