[FIX] db_exist method works as expected

bzr revid: chs@tinyerp.com-20091201133214-8c6i1ohk5t5u79dz
This commit is contained in:
Christophe Simonis 2009-12-01 14:32:14 +01:00
parent 229c73d741
commit e345e91365
2 changed files with 11 additions and 5 deletions

View File

@ -286,11 +286,8 @@ class db(netsvc.Service):
return True
def db_exist(self, db_name):
try:
db = sql_db.db_connect(db_name)
return True
except:
return False
## Not True: in fact, check if connection to database is possible. The database may exists
return bool(sql_db.db_connect(db_name))
def list(self):
db = sql_db.db_connect('template1')

View File

@ -310,6 +310,15 @@ class Connection(object):
def serialized_cursor(self):
return self.cursor(True)
def __nonzero__(self):
"""Check if connection is possible"""
try:
cr = self.cursor()
cr.close()
return True
except:
return False
_dsn = ''
for p in ('host', 'port', 'user', 'password'):