diff options
Diffstat (limited to 'odoo/tools/sql.py')
| -rw-r--r-- | odoo/tools/sql.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py new file mode 100644 index 00000000000..43c54c1a28a --- /dev/null +++ b/odoo/tools/sql.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +def drop_view_if_exists(cr, viewname): + cr.execute("DROP view IF EXISTS %s CASCADE" % (viewname,)) + cr.commit() + +def escape_psql(to_escape): + return to_escape.replace('\\', r'\\').replace('%', '\%').replace('_', '\_') + +def pg_varchar(size=0): + """ Returns the VARCHAR declaration for the provided size: + + * If no size (or an empty or negative size is provided) return an + 'infinite' VARCHAR + * Otherwise return a VARCHAR(n) + + :type int size: varchar size, optional + :rtype: str + """ + if size: + if not isinstance(size, int): + raise ValueError("VARCHAR parameter should be an int, got %s" % type(size)) + if size > 0: + return 'VARCHAR(%d)' % size + return 'VARCHAR' |
