fixed issue 1700:DAL contains is not working on MSSQL

This commit is contained in:
mdipierro
2013-10-03 08:33:57 -05:00
parent 302a985aa7
commit c5b9b4d723
2 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.6.4-stable+timestamp.2013.10.03.08.18.43 Version 2.6.4-stable+timestamp.2013.10.03.08.33.04
+11 -3
View File
@@ -1403,12 +1403,15 @@ class BaseAdapter(ConnectionPool):
def COMMA(self, first, second): def COMMA(self, first, second):
return '%s, %s' % (self.expand(first), self.expand(second)) return '%s, %s' % (self.expand(first), self.expand(second))
def CAST(self, first, second):
return 'CAST(%s AS %s)' % (first, second)
def expand(self, expression, field_type=None): def expand(self, expression, field_type=None):
if isinstance(expression, Field): if isinstance(expression, Field):
out = '%s.%s' % (expression.table._tablename, expression.name) out = '%s.%s' % (expression.table._tablename, expression.name)
if field_type == 'string' and not expression.type in ( if field_type == 'string' and not expression.type in (
'string','text','json','password'): 'string','text','json','password'):
out = 'CAST(%s AS %s)' % (out, self.types['text']) out = self.CAST(out, self.types['text'])
return out return out
elif isinstance(expression, (Expression, Query)): elif isinstance(expression, (Expression, Query)):
first = expression.first first = expression.first
@@ -2737,14 +2740,16 @@ class PostgreSQLAdapter(BaseAdapter):
def LIKE(self,first,second): def LIKE(self,first,second):
args = (self.expand(first), self.expand(second,'string')) args = (self.expand(first), self.expand(second,'string'))
if not first.type in ('string', 'text', 'json'): if not first.type in ('string', 'text', 'json'):
return '(CAST(%s AS CHAR(%s)) LIKE %s)' % (args[0], first.length, args[1]) return '(%s LIKE %s)' % (
self.CAST(args[0], 'CHAR(%s)' % first.length), args[1])
else: else:
return '(%s LIKE %s)' % args return '(%s LIKE %s)' % args
def ILIKE(self,first,second): def ILIKE(self,first,second):
args = (self.expand(first), self.expand(second,'string')) args = (self.expand(first), self.expand(second,'string'))
if not first.type in ('string', 'text', 'json'): if not first.type in ('string', 'text', 'json'):
return '(CAST(%s AS CHAR(%s)) LIKE %s)' % (args[0], first.length, args[1]) return '(%s LIKE %s)' % (
self.CAST(args[0], 'CHAR(%s)' % first.length), args[1])
else: else:
return '(%s ILIKE %s)' % args return '(%s ILIKE %s)' % args
@@ -3181,6 +3186,9 @@ class MSSQLAdapter(BaseAdapter):
def ALLOW_NULL(self): def ALLOW_NULL(self):
return ' NULL' return ' NULL'
def CAST(self, first, second):
return first # apparently no cast necessary in MSSQL
def SUBSTRING(self,field,parameters): def SUBSTRING(self,field,parameters):
return 'SUBSTRING(%s,%s,%s)' % (self.expand(field), parameters[0], parameters[1]) return 'SUBSTRING(%s,%s,%s)' % (self.expand(field), parameters[0], parameters[1])