@@ -77,32 +77,38 @@ def render(self):
7777 if self .cell_type == NotebookCell .SQL :
7878 execution_start = timezone .now ()
7979
80+ results = []
8081 with connection .cursor () as cursor :
81- try :
82- cursor .execute (self .contents )
83-
84- if cursor .description :
85- columns = [col [0 ] for col in cursor .description ]
86- rows = cursor .fetchall ()
87-
82+ queries = self .contents .split (";\n " ) # Eh.
83+ for query in queries :
84+ try :
85+ cursor .execute (query )
86+
87+ if cursor .description :
88+ columns = [col [0 ] for col in cursor .description ]
89+ rows = cursor .fetchall ()
90+
91+ result = render_to_string (
92+ "notebooks/sql.html" ,
93+ {
94+ "columns" : columns ,
95+ "rows" : rows ,
96+ },
97+ )
98+ results .append (result )
99+ else :
100+ # Not an error, but the formatting is helpful.
101+ result = render_to_string ("notebooks/sql_error.html" , {"error" : str (cursor .statusmessage )})
102+ results .append (result )
103+ except Exception as e :
88104 result = render_to_string (
89- "notebooks/sql .html" ,
105+ "notebooks/sql_error .html" ,
90106 {
91- "columns" : columns ,
92- "rows" : rows ,
107+ "error" : str (e ),
93108 },
94109 )
95- else :
96- # Not an error, but the formatting is helpful.
97- result = render_to_string ("notebooks/sql_error.html" , {"error" : str (cursor .statusmessage )})
98- except Exception as e :
99- result = render_to_string (
100- "notebooks/sql_error.html" ,
101- {
102- "error" : str (e ),
103- },
104- )
105- self .rendering = result
110+ results .append (result )
111+ self .rendering = "\n " .join (results )
106112 self .execution_time = timezone .now () - execution_start
107113
108114 elif self .cell_type == NotebookCell .MARKDOWN :
0 commit comments