diff options
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; -} - |