summaryrefslogtreecommitdiff
path: root/sqlbox/view.php
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:43:27 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:43:27 +0100
commit639db3eee5df60f520b33dcb0c8f0e1ffc80fd49 (patch)
tree2d2670ecbe2ccd7a28aa227e55337436d09deda0 /sqlbox/view.php
parentd1aaba539247b3602d8e7351ecdc694c5cdc33d1 (diff)
downloadsqltutor-plugin-639db3eee5df60f520b33dcb0c8f0e1ffc80fd49.tar.gz
sqltutor-plugin-639db3eee5df60f520b33dcb0c8f0e1ffc80fd49.tar.bz2
sqltutor-plugin-639db3eee5df60f520b33dcb0c8f0e1ffc80fd49.zip
sqlbox/view: Check against example query only if available
Diffstat (limited to 'sqlbox/view.php')
-rw-r--r--sqlbox/view.php11
1 files changed, 9 insertions, 2 deletions
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!");