def distinct(self):
return CompoundClause(None,"DISTINCT", self)
def between(self, cleft, cright):
- return between_(self, cleft, cright)
+ return between_(self, self._check_literal(cleft), self._check_literal(cright))
def op(self, operator):
return lambda other: self._compare(operator, other)
# and here come the math operators:
return self._operate('/', other)
def _bind_param(self, obj):
return BindParamClause('literal', obj, shortname=None, type=self.type)
+ def _check_literal(self, other):
+ if _is_literal(other):
+ return self._bind_param(other)
+ else:
+ return other
def _compare(self, operator, obj):
if obj is None or isinstance(obj, Null):
if operator == '=':
return BooleanExpression(self._compare_self(), null(), 'IS NOT')
else:
raise exceptions.ArgumentError("Only '='/'!=' operators can be used with NULL")
- elif _is_literal(obj):
- obj = self._bind_param(obj)
+ else:
+ obj = self._check_literal(obj)
return BooleanExpression(self._compare_self(), obj, operator, type=self._compare_type(obj))
def _operate(self, operator, obj):
# and the MySQL engine
check_results(mysql.dialect(), ['NUMERIC(10, 2)', 'NUMERIC(12, 9)', 'DATE', 'TEXT', 'VARCHAR(20)'], '%s')
+
+ def testdatebetween(self):
+ import datetime
+ table = Table('dt', metadata,
+ Column('date', Date))
+ self.runtest(table.select(table.c.date.between(datetime.date(2006,6,1), datetime.date(2006,6,5))), "SELECT dt.date FROM dt WHERE dt.date BETWEEN :dt_date AND :dt_da_1", checkparams={'dt_date':datetime.date(2006,6,1), 'dt_da_1':datetime.date(2006,6,5)})
+
class CRUDTest(SQLTest):
def testinsert(self):
# generic insert, will create bind params for all columns
checkparams = {'myid':3, 'name':'jack', 'description':'mydescription'}
)
+
def testinsertexpression(self):
self.runtest(insert(table1), "INSERT INTO mytable (myid) VALUES (lala())", params=dict(myid=func.lala()))