Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This works
>>> print select('person', where={'id in': ('foo', 'bar')}) SELECT * FROM "person" WHERE "id" IN ('foo', 'bar')
But this doesn't
>>> print select('person', where={'id in': (1, 2, 3)}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mosql/util.py", line 819, in __call__ return self.stringify(*positional_values, **clause_args) File "mosql/util.py", line 815, in stringify return self.format(clause_args) File "mosql/util.py", line 801, in format return self.statement.format(clause_args) File "mosql/util.py", line 752, in format pieces.append(clause.format(arg)) File "mosql/util.py", line 679, in format x = formatter(x) File "mosql/util.py", line 359, in joiner_wrapper return f(x) File "mosql/util.py", line 519, in build_where return _build_condition(x, identifier, value) File "mosql/util.py", line 464, in _build_condition v = paren(concat_by_comma(v)) File "mosql/util.py", line 359, in joiner_wrapper return f(x) File "mosql/util.py", line 383, in concat_by_comma return ', '.join(i) TypeError: sequence item 0: expected string, int found
because join works only when the sequence contains str (and unicode) instances.
join
str
unicode
It seems pretty reasonable to coerce before concatenating values:
@joiner def concat_by_comma(i): '''A joiner function which concats the iterable by ``,`` (comma).''' return ', '.join(str(v) for v in i)
concat_by_space, concat_by_or and concat_by_and are all similar, I believe. Maybe extract the logic into a decorator?
concat_by_space
concat_by_or
concat_by_and
There may be some encoding issues, too. I would rather use unicode instead of str, but you will need to add some version detection if so.
The text was updated successfully, but these errors were encountered:
It is a regression. I'm checking.
Sorry, something went wrong.
20ba8fc
No branches or pull requests
uranusjr commentedDec 17, 2013
This works
But this doesn't
because
join
works only when the sequence containsstr
(andunicode
) instances.It seems pretty reasonable to coerce before concatenating values:
concat_by_space
,concat_by_or
andconcat_by_and
are all similar, I believe. Maybe extract the logic into a decorator?There may be some encoding issues, too. I would rather use
unicode
instead ofstr
, but you will need to add some version detection if so.The text was updated successfully, but these errors were encountered: