diff options
| author | Raphael Collet <rco@openerp.com> | 2016-09-02 15:58:39 +0200 |
|---|---|---|
| committer | Raphael Collet <rco@openerp.com> | 2016-09-02 17:28:12 +0200 |
| commit | 9e64f9f9514194d74e166b032add8511182f2677 (patch) | |
| tree | 5086710c04c6b923be18a6d1d97b3f0f3a2a9c4a /odoo/tools/sql.py | |
| parent | 11812b0b9e82b2b1b9041d8250ce01e7b4a5f7ee (diff) | |
[REF] openerp: move `openerp` to `odoo`
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' |
