[FIX] handle the case when the database template1 is not in UTF8

bzr revid: christophe@cobalt-20081229171259-1ajgi2bdv1pkr4sw
This commit is contained in:
Christophe Simonis 2008-12-29 18:12:59 +01:00
parent be6cd6de77
commit 028a994fe9
1 changed files with 5 additions and 5 deletions

View File

@ -245,14 +245,14 @@ class db(netsvc.Service):
import pwd
db_user = pwd.getpwuid(os.getuid())[0]
if not db_user:
cr.execute("select usename from pg_user where usesysid=(select datdba from pg_database where datname=%s)", (tools.config["db_name"],))
cr.execute("select decode(usename, 'escape') from pg_user where usesysid=(select datdba from pg_database where datname=%s)", (tools.config["db_name"],))
res = cr.fetchone()
db_user = res and res[0]
db_user = res and str(res[0])
if db_user:
cr.execute("select datname from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres')", (db_user,))
cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres')", (db_user,))
else:
cr.execute("select datname from pg_database where datname not in('template0', 'template1','postgres')")
res = [name for (name,) in cr.fetchall()]
cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres')")
res = [str(name) for (name,) in cr.fetchall()]
cr.close()
except:
res = []