Skip to content

Commit

Permalink
Encode EXPLAIN SQL before sending to datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
drmalex07 authored and amercader committed Feb 9, 2016
1 parent af3fdd1 commit 2502821
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ckanext/datastore/helpers.py
Expand Up @@ -79,7 +79,7 @@ def _get_table_names_from_plan(plan):
return table_names

result = context['connection'].execute(
'EXPLAIN (FORMAT JSON) {0}'.format(sql)).fetchone()
'EXPLAIN (FORMAT JSON) {0}'.format(sql.encode('utf-8'))).fetchone()

table_names = []

Expand Down
5 changes: 5 additions & 0 deletions ckanext/datastore/tests/test_helpers.py
@@ -1,3 +1,5 @@
# -*- encoding: utf-8 -*-

import pylons
import sqlalchemy.orm as orm
import nose
Expand Down Expand Up @@ -79,6 +81,7 @@ def setup_class(cls):
'CREATE TABLE test_a (id_a text)',
'CREATE TABLE test_b (id_b text)',
'CREATE TABLE "TEST_C" (id_c text)',
'CREATE TABLE test_d ("α/α" integer)', # non-ascii name for a column
]
for create_table_sql in create_tables:
cls.Session.execute(create_table_sql)
Expand Down Expand Up @@ -109,6 +112,8 @@ def test_get_table_names(self):
test_b) AS b,
test_a AS a''', ['test_a', 'test_b', 'TEST_C']),
('INSERT INTO test_a VALUES (\'a\')', ['test_a']),
('SELECT "α/α" FROM test_d', ['test_d']),
('SELECT "α/α" FROM test_d WHERE "α/α" > 1000', ['test_d']),
]

context = {
Expand Down

0 comments on commit 2502821

Please sign in to comment.