+_operators = {
+ '=': '==',
+}
+
+def _translate_condition(table, condition, params):
+ field = condition.left.get_real_name()
+
+ operator = list(filter(lambda t: t.ttype == sqlparse.tokens.Comparison, condition.tokens))[0]
+ if operator.value in _operators:
+ operator = _operators[operator.value]
+ else:
+ operator = operator.value
+
+ value = condition.right.value
+ if value.startswith(':'):
+ # Value is a parameters
+ value = value[1:]
+ if value in params:
+ # Cast value to the column type
+ coltype = table.coltypes[field]
+ if coltype == 'string':
+ params[value] = str(params[value])
+ elif coltype.startswith('int'):
+ params[value] = int(params[value])
+ elif coltype.startswith('float'):
+ params[value] = float(params[value])
+
+ translated = "{left} {operator} {right}".format(left=field, operator=operator, right=value)
+ return translated, params
+