[FIX] handle the case when the database template1 is not in UTF8
authorChristophe Simonis <christophe@cobalt>
Mon, 29 Dec 2008 17:12:59 +0000 (18:12 +0100)
committerChristophe Simonis <christophe@cobalt>
Mon, 29 Dec 2008 17:12:59 +0000 (18:12 +0100)
bzr revid: christophe@cobalt-20081229171259-1ajgi2bdv1pkr4sw

bin/service/web_services.py

index eef0252..5ec9603 100644 (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 = []