Permalink
Browse files

sql with no return data doesnt explode

  • Loading branch information...
1 parent bed515d commit 88487d52c5d05e77ff6b82bea19896ea7d06cfc2 @chrisclark chrisclark committed Feb 3, 2014
Showing with 6 additions and 1 deletion.
  1. +5 −0 explorer/tests/test_views.py
  2. +1 −1 explorer/utils.py
@@ -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"))
View
@@ -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

0 comments on commit 88487d5

Please sign in to comment.