Skip to content

Commit

Permalink
Escape string enum fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Mar 22, 2019
1 parent 2beeac0 commit f72814f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clickhouse_driver/util/escape.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def escape_param(item):
return "(%s)" % ', '.join(text_type(escape_param(x)) for x in item)

elif isinstance(item, Enum):
return item.value
return escape_param(item.value)

elif isinstance(item, UUID):
return "'%s'" % str(item)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from decimal import Decimal
from uuid import UUID

from enum import IntEnum
from enum import IntEnum, Enum

from tests.testcase import BaseTestCase

Expand Down Expand Up @@ -132,6 +132,17 @@ class A(IntEnum):
rv = self.client.execute(self.double_tpl, params)
self.assertEqual(rv, [(-1, 2)])

class A(Enum):
hello = 'hello'
world = 'world'

params = {'x': A.hello, 'y': A.world}

self.assert_subst(self.double_tpl, params, "SELECT 'hello', 'world'")

rv = self.client.execute(self.double_tpl, params)
self.assertEqual(rv, [('hello', 'world')])

def test_float(self):
params = {'x': 1e-12, 'y': 123.45}

Expand Down

0 comments on commit f72814f

Please sign in to comment.