From 639db3eee5df60f520b33dcb0c8f0e1ffc80fd49 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 23 Nov 2012 10:43:27 +0100 Subject: sqlbox/view: Check against example query only if available --- sqlbox/view.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 5c7c4e1..0c7c841 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,6 +78,8 @@ $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); $data = $form->get_data(); +$correct = true; + echo $OUTPUT->heading('SQL Query: '.$data->sqlbox_query); if (isset($data->sqlbox_query)) { $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); @@ -85,12 +87,17 @@ if (isset($data->sqlbox_query)) { error("Failed to connect to sqlbox db"); $table = db_get_table_from_query($db, $data->sqlbox_query); - $table_orig = db_get_table_from_query($db, $sqlbox->query); + if (strlen($sqlbox->query) > 0) { + $table_orig = db_get_table_from_query($db, $sqlbox->query); + if ($table->data != $table_orig->data || + $table->head != $table_orig->head) + $correct = false; + } pg_close($db); echo html_writer::table($table); - if ($table->data == $table_orig->data && $table->head == $table->head) + if ($correct) echo $OUTPUT->heading("Correct!"); else echo $OUTPUT->heading("Incorrect!"); -- cgit