diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-23 10:46:44 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-23 10:47:38 +0100 |
commit | 744c06b8fcfc3a2d1540eeef44c84522b58475af (patch) | |
tree | 887dae694c6788a2436107a82c48d84d749c421f /sqlbox | |
parent | 639db3eee5df60f520b33dcb0c8f0e1ffc80fd49 (diff) | |
download | sqltutor-plugin-744c06b8fcfc3a2d1540eeef44c84522b58475af.tar.gz sqltutor-plugin-744c06b8fcfc3a2d1540eeef44c84522b58475af.tar.bz2 sqltutor-plugin-744c06b8fcfc3a2d1540eeef44c84522b58475af.zip |
sqlbox: Move db_table_from_query to locallib.php
Diffstat (limited to 'sqlbox')
-rw-r--r-- | sqlbox/locallib.php | 17 | ||||
-rw-r--r-- | sqlbox/view.php | 20 |
2 files changed, 19 insertions, 18 deletions
diff --git a/sqlbox/locallib.php b/sqlbox/locallib.php index 3820cec..f335b9a 100644 --- a/sqlbox/locallib.php +++ b/sqlbox/locallib.php @@ -38,3 +38,20 @@ defined('MOODLE_INTERNAL') || die(); //function sqlbox_do_something_useful(array $things) { // return new stdClass(); //} + +function db_table_from_query($db, $query) { + $table = new html_table; + $result = pg_query($db, $query); + if (!$result) + error("Query failed: ".pg_last_error($db)); + + $table = new html_table; + $n = pg_num_fields($result); + for ($i = 0; $i < $n; $i++) + $table->head[] = pg_field_name($result, $i); + $table->align = array_fill(0, $n, 'left'); + while ($row = pg_fetch_row($result)) + $table->data[] = $row; + + return $table; +} diff --git a/sqlbox/view.php b/sqlbox/view.php index 0c7c841..8d6f29a 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -31,6 +31,7 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/sqlbox_form.php'); $id = optional_param('id', 0, PARAM_INT); // course_module ID, or @@ -86,7 +87,7 @@ if (isset($data->sqlbox_query)) { if (!db) error("Failed to connect to sqlbox db"); - $table = db_get_table_from_query($db, $data->sqlbox_query); + $table = db_table_from_query($db, $data->sqlbox_query); if (strlen($sqlbox->query) > 0) { $table_orig = db_get_table_from_query($db, $sqlbox->query); if ($table->data != $table_orig->data || @@ -107,20 +108,3 @@ if (isset($data->sqlbox_query)) { echo $OUTPUT->footer(); -function db_get_table_from_query($db, $query) { - $table = new html_table; - $result = pg_query($db, $query); - if (!$result) - error("Query failed: ".pg_last_error($db)); - - $table = new html_table; - $n = pg_num_fields($result); - for ($i = 0; $i < $n; $i++) - $table->head[] = pg_field_name($result, $i); - $table->align = array_fill(0, $n, 'left'); - while ($row = pg_fetch_row($result)) - $table->data[] = $row; - - return $table; -} - |