Skip to content

Commit

Permalink
Merge pull request #182 from kensho/sanitize_operators
Browse files Browse the repository at this point in the history
Sanitize operators
  • Loading branch information
Ostico committed Apr 10, 2016
2 parents cf9345e + 333b257 commit 2285eb4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pyorient/ogm/query.py
Expand Up @@ -318,7 +318,7 @@ def filter_string(self, expression_root):
elif op is Operator.Between:
far_right = PropertyEncoder.encode_value(expression_root.operands[2])
return u'{0} BETWEEN {1} and {2}'.format(
left_str, right, far_right)
left_str, PropertyEncoder.encode_value(right), far_right)
elif op is Operator.Contains:
if isinstance(right, LogicalConnective):
return u'{0} contains({1})'.format(
Expand All @@ -327,19 +327,21 @@ def filter_string(self, expression_root):
return u'{} in {}'.format(
PropertyEncoder.encode_value(right), left_str)
elif op is Operator.EndsWith:
return u'{0} like \'%{1}\''.format(left_str, right)
return u'{0} like {1}'.format(left_str, PropertyEncoder.encode_value('%' + right))
elif op is Operator.Is:
if not right: # :)
return '{0} is null'.format(left_str)
elif op is Operator.Like:
return u'{0} like \'{1}\''.format(
left_str, right)
return u'{0} like {1}'.format(
left_str, PropertyEncoder.encode_value(right))
elif op is Operator.Matches:
return u'{0} matches \'{1}\''.format(
left_str, right)
return u'{0} matches {1}'.format(
left_str, PropertyEncoder.encode_value(right))
elif op is Operator.StartsWith:
return u'{0} like \'{1}%\''.format(
left_str, right)
return u'{0} like {1}'.format(
left_str, PropertyEncoder.encode_value(right + '%'))
else:
raise AssertionError('Unhandled Operator type: {}'.format(op))
else:
return u'{0} {1} {2}'.format(
self.filter_string(left)
Expand Down

0 comments on commit 2285eb4

Please sign in to comment.