[FIX] fix problem create db when already exists

bzr revid: pja@tinyerp.com-20121112103321-v39900rc6tu0pvmb
This commit is contained in:
Jalpesh Patel (OpenERP) 2012-11-12 16:03:21 +05:30
parent be03940d64
commit 8e58d8d17c
1 changed files with 6 additions and 0 deletions

View File

@ -120,6 +120,12 @@ class db(netsvc.ExportService):
db = sql_db.db_connect('postgres')
cr = db.cursor()
chosen_template = tools.config['db_template']
cr.execute("""SELECT datname
FROM pg_database
WHERE datname = %s """,
(name,))
if cr.fetchall():
raise openerp.exceptions.Warning(" %s database already exists!" % name )
try:
cr.autocommit(True) # avoid transaction block
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (name, chosen_template))