summaryrefslogtreecommitdiff
path: root/odoo/tools/sql.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-09-12 12:09:11 +0200
committerChristophe Simonis <chs@odoo.com>2017-09-12 12:09:11 +0200
commitc5f680200cd5a213b71584734f266630fd25cdfa (patch)
tree0ac30ee86a7d99103e7d69f1f0ffb5fbbee9851b /odoo/tools/sql.py
parente7205b7992f55ef2cf9df9d8f2b71fafe9ed6348 (diff)
parentd08b4407be3cf9b404087056a413fbdc9eecbd9d (diff)
[MERGE] forward port branch saas-17 up to d08b4407be3
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 ff52c5b580a..7e8f69a4168 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),