From 484b8e5cc939af947728e1e2fa2482936782e42e Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 9 Jun 2013 16:41:46 -0500 Subject: [PATCH] possibly fixed issue 1446:contains/cast to string problem --- VERSION | 2 +- gluon/dal.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index 5ef83a59..87d0cfb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.5.1-stable+timestamp.2013.06.09.16.30.03 +Version 2.5.1-stable+timestamp.2013.06.09.16.41.01 diff --git a/gluon/dal.py b/gluon/dal.py index 9b303322..b08cf609 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -1309,7 +1309,7 @@ class BaseAdapter(ConnectionPool): return ftype in ('integer','boolean','double','bigint') or \ ftype.startswith('decimal') - def REPLACE(self, first, (second, third)): + def REPLACE(self, first, (second, third)): return 'REPLACE(%s,%s,%s)' % (self.expand(first,'string'), self.expand(second,'string'), self.expand(third,'string')) @@ -1356,22 +1356,28 @@ class BaseAdapter(ConnectionPool): def expand(self, expression, field_type=None): if isinstance(expression, Field): - return '%s.%s' % (expression.tablename, expression.name) + out = '%s.%s' % (expression.tablename, expression.name) + if field_type == 'string': + out = 'CAST(%s AS %s)' % (out, self.types['text']) + return out elif isinstance(expression, (Expression, Query)): first = expression.first second = expression.second op = expression.op optional_args = expression.optional_args or {} if not second is None: - return op(first, second, **optional_args) + out = op(first, second, **optional_args) elif not first is None: - return op(first,**optional_args) + out = op(first,**optional_args) elif isinstance(op, str): if op.endswith(';'): op=op[:-1] - return '(%s)' % op + out = '(%s)' % op else: - return op() + out = op() + if field_type == 'string': + out = 'CAST(%s AS %s)' % (out, self.types['text']) + return out elif field_type: return str(self.represent(expression,field_type)) elif isinstance(expression,(list,tuple)):