summaryrefslogtreecommitdiff
path: root/odoo/tools/sql.py
diff options
context:
space:
mode:
authorStefan Rijnhart <stefan@opener.am>2018-06-12 09:44:26 +0200
committerRaphael Collet <rco@odoo.com>2018-08-16 10:33:06 +0200
commitb3824aa6cbecc97fc0cd54773417045e69adc87a (patch)
tree30d0939e6bf380f0b7e149d499c63ea444dcf0b2 /odoo/tools/sql.py
parent6327b8f97fef6640c29339d3b0187c40036cb986 (diff)
[RFR] Hide implementation of constraint definition storage, courtesy of Raphael Collet
Diffstat (limited to 'odoo/tools/sql.py')
-rw-r--r--odoo/tools/sql.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py
index b1c7ecbbf3a..2a0594b7d34 100644
--- a/odoo/tools/sql.py
+++ b/odoo/tools/sql.py
@@ -120,17 +120,13 @@ def drop_not_null(cr, tablename, columnname):
def constraint_definition(cr, tablename, constraintname):
""" Return the given constraint's definition. """
- cr.execute('SELECT pg_get_constraintdef(c.oid) FROM pg_constraint c '
- 'JOIN pg_class t ON t.oid = c.conrelid '
- 'WHERE t.relname = %s AND conname=%s', (tablename, constraintname,))
- return cr.fetchone()[0] if cr.rowcount else None
-
-def constraint_comment(cr, tablename, constraintname):
- """ Return the given constraint's comment. """
- cr.execute('SELECT d.description FROM pg_description d '
- 'JOIN pg_constraint c ON c.oid = d.objoid '
- 'JOIN pg_class t ON t.oid = c.conrelid '
- 'WHERE t.relname = %s AND conname = %s;', (tablename, constraintname,))
+ query = """
+ SELECT COALESCE(d.description, pg_get_constraintdef(c.oid))
+ FROM pg_constraint c
+ JOIN pg_class t ON t.oid = c.conrelid
+ LEFT JOIN pg_description d ON c.oid = d.objoid
+ WHERE t.relname = %s AND conname = %s;"""
+ cr.execute(query, (tablename, constraintname))
return cr.fetchone()[0] if cr.rowcount else None
def add_constraint(cr, tablename, constraintname, definition):
@@ -145,7 +141,7 @@ def add_constraint(cr, tablename, constraintname, definition):
except Exception:
msg = "Table %r: unable to add constraint %r!\n" \
"If you want to have it, you should update the records and execute manually:\n%s"
- _schema.warning(msg, tablename, constraintname, query, exc_info=True)
+ _schema.warning(msg, tablename, constraintname, query1, exc_info=True)
def drop_constraint(cr, tablename, constraintname):
""" drop the given constraint. """