summaryrefslogtreecommitdiff
path: root/odoo/tools/sql.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-09-11 14:52:36 +0200
committerChristophe Simonis <chs@odoo.com>2017-09-11 14:55:49 +0200
commitfdc4ef97c9d09ce07aa2e747041d973a3e607af5 (patch)
tree74bc099e16608facd2e1c5872d5112da208f0372 /odoo/tools/sql.py
parent45d706a607b218200099e6d62f2d4a7539ebd728 (diff)
[FIX] core: only check table existance in public schema
This allow the use of tables defined in other schemas, like `domains`, already defined in `information_schema`. See #16651
Diffstat (limited to 'odoo/tools/sql.py')
-rw-r--r--odoo/tools/sql.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py
index d15bd027176..82568cdb92f 100644
--- a/odoo/tools/sql.py
+++ b/odoo/tools/sql.py
@@ -24,19 +24,19 @@ _CONFDELTYPES = {
def existing_tables(cr, tablenames):
""" Return the names of existing tables among ``tablenames``. """
query = """
- SELECT relname
- FROM pg_class
- WHERE relname IN %s
- AND relkind IN ('r', 'v', 'm')
+ SELECT c.relname
+ FROM pg_class c
+ JOIN pg_namespace n ON (n.oid = c.relnamespace)
+ WHERE c.relname IN %s
+ AND c.relkind IN ('r', 'v', 'm')
+ AND n.nspname = 'public'
"""
cr.execute(query, [tuple(tablenames)])
return [row[0] for row in cr.fetchall()]
def table_exists(cr, tablename):
""" Return whether the given table exists. """
- query = "SELECT 1 FROM pg_class WHERE relkind IN ('r', 'v', 'm') AND relname=%s"
- cr.execute(query, (tablename,))
- return cr.rowcount
+ return len(existing_tables(cr, {tablename})) == 1
def table_kind(cr, tablename):
""" Return the kind of a table: ``'r'`` (regular table), ``'v'`` (view),