Skip to content

Commit

Permalink
sql with no return data doesnt explode
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisclark committed Feb 3, 2014
1 parent bed515d commit 88487d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions explorer/tests/test_views.py
Expand Up @@ -109,6 +109,11 @@ def test_playground_renders_with_posted_sql(self):
self.assertTemplateUsed(resp, 'explorer/play.html')
self.assertContains(resp, 'select 1;')

def test_query_with_no_resultset_doesnt_throw_error(self):
query = SimpleQueryFactory(sql="")
resp = self.client.get('%s?query_id=%s' % (reverse("explorer_playground"), query.id))
self.assertTemplateUsed(resp, 'explorer/play.html')

def test_admin_required(self):
self.client.logout()
resp = self.client.get(reverse("explorer_playground"))
Expand Down
2 changes: 1 addition & 1 deletion explorer/utils.py
Expand Up @@ -36,7 +36,7 @@ def execute_query(sql):

def execute_and_fetch_query(sql):
cursor, duration = execute_query(sql)
headers = [d[0] for d in cursor.description]
headers = [d[0] for d in cursor.description] if cursor.description else ['--']
data = [[x.encode('utf-8') if type(x) is unicode else x for x in list(r)] for r in cursor.fetchall()]
return headers, data, duration, None

Expand Down

0 comments on commit 88487d5

Please sign in to comment.