From 9d50e1da6601bee2582f76ad850eaba0d5d0b9c0 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Tue, 20 Nov 2012 15:16:44 +0100 Subject: Add input box for sql string. --- sqlbox/view.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index a82e9c8..4580f16 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -74,5 +74,12 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); +$form = < + +EOF; + +echo $OUTPUT->heading($form); + // Finish the page echo $OUTPUT->footer(); -- cgit From 13acd7742a9287249c1f0de15435e663f9c8cc28 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Tue, 20 Nov 2012 15:20:44 +0100 Subject: Fix multiline string. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 4580f16..e2330e1 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -74,7 +74,7 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); -$form = < EOF; -- cgit From db77666426e101c2bb374947af6193570b564e10 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 20 Nov 2012 20:27:07 +0100 Subject: sqlbox: Add a simple form using formslib --- sqlbox/view.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index e2330e1..96c3e36 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__).'/sqlbox_form.php'); $id = optional_param('id', 0, PARAM_INT); // course_module ID, or $n = optional_param('n', 0, PARAM_INT); // sqlbox instance ID - it should be named as the first character of the module @@ -74,12 +75,8 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); -$form = << - -EOF; - -echo $OUTPUT->heading($form); +$form = new mod_sqlbox_form(NULL, array()); +$form->display(); // Finish the page echo $OUTPUT->footer(); -- cgit From 731c82ea796e95d6c717deaad4bd164dba65ad6f Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 07:09:51 +0100 Subject: Add raw data output. --- sqlbox/view.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 96c3e36..123c21f 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,5 +78,10 @@ echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form(NULL, array()); $form->display(); +$data = $form->get_data(); + +if ($data) + print_r($data); + // Finish the page echo $OUTPUT->footer(); -- cgit From 597af18edf0c143d78797381226f28157a470617 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 07:11:27 +0100 Subject: change data output for debug purpos. --- sqlbox/view.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 123c21f..426e1d9 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,10 +78,7 @@ echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form(NULL, array()); $form->display(); -$data = $form->get_data(); - -if ($data) - print_r($data); +print_r($form->get_data()); // Finish the page echo $OUTPUT->footer(); -- cgit From 4e71a612e6449cf022b948e0d1db4fa8e258281d Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 09:25:12 +0100 Subject: sqlbox/view: Pass page url to form --- sqlbox/view.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 426e1d9..ee30811 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -75,9 +75,8 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); -$form = new mod_sqlbox_form(NULL, array()); +$form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); - print_r($form->get_data()); // Finish the page -- cgit From f1234ad5c967e2fc3f18662d32362cdfc5a93495 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 10:49:44 +0100 Subject: wip --- sqlbox/view.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index ee30811..0f371b8 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -77,7 +77,24 @@ echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); -print_r($form->get_data()); +$data = $form->get_data(); + +echo $OUTPUT->heading('Query: '.$data->query); +if (isset($data->query)) { + $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); + if (!db) + error("Failed to connect to sqlbox db"); + + $result = pg_query($db, $data->query); + if (!$result) + error("Query failed!"); + + while($row=pg_fetch_row($result)){ + print_r($row); + echo "
\n"; + } +} + // Finish the page echo $OUTPUT->footer(); -- cgit From 4dd307bf59e4245bfe982f45b01e72f9dcd02136 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:02:29 +0100 Subject: sqlbox: Add support for issuing query to database --- sqlbox/view.php | 1 - 1 file changed, 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 0f371b8..b6d4f45 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -95,6 +95,5 @@ if (isset($data->query)) { } } - // Finish the page echo $OUTPUT->footer(); -- cgit From 93269a59dcc12a69969fdee366cc491fd8c4c35c Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:03:30 +0100 Subject: sqlbox: Remove "Yay! It works!" --- sqlbox/view.php | 1 - 1 file changed, 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index b6d4f45..f15c5e4 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -73,7 +73,6 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own } // Replace the following lines with you own code -echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); -- cgit From 854159ddbf2c284118a83495e215a178f2bf39e9 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:48:17 +0100 Subject: sqlbox: s/Query/SQL Query/ --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index f15c5e4..e9e4ba6 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,7 +78,7 @@ $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); $data = $form->get_data(); -echo $OUTPUT->heading('Query: '.$data->query); +echo $OUTPUT->heading('SQL Query: '.$data->query); if (isset($data->query)) { $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); if (!db) -- cgit From a4d8c7f7b7670dd7ac2a8c09441b522ea4fa11a4 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 11:58:37 +0100 Subject: Query output format as table. --- sqlbox/view.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index e9e4ba6..c6f99a1 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,10 +88,15 @@ if (isset($data->query)) { if (!$result) error("Query failed!"); + echo ""; while($row=pg_fetch_row($result)){ - print_r($row); - echo "
\n"; + echo ""; + foreach($row as $val) { + echo ""; + } + echo ""; } + echo "
$val
"; } // Finish the page -- cgit From 8143bfc345cd7ac03be51456588860d420f4fdd8 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 11:59:39 +0100 Subject: Fix wrong td tag. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index c6f99a1..0091807 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -92,7 +92,7 @@ if (isset($data->query)) { while($row=pg_fetch_row($result)){ echo ""; foreach($row as $val) { - echo "$val"; + echo "$val"; } echo ""; } -- cgit From 04e6e490862db2c164526b3aede92c7e9d8eb316 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 12:00:43 +0100 Subject: Add border to output table. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 0091807..8cf6848 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,7 +88,7 @@ if (isset($data->query)) { if (!$result) error("Query failed!"); - echo ""; + echo "
"; while($row=pg_fetch_row($result)){ echo ""; foreach($row as $val) { -- cgit From ce4fa77b60ed3aad6dcd09dbd48fd7b119bc1261 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 12:04:06 +0100 Subject: sqlbox: Show query field names --- sqlbox/view.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 8cf6848..dd20fb9 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -89,6 +89,10 @@ if (isset($data->query)) { error("Query failed!"); echo "
"; + $n = pg_num_fields($result); + for ($i = 0; $i < $n; $i++) { + echo ""; + } while($row=pg_fetch_row($result)){ echo ""; foreach($row as $val) { -- cgit From ac24b67ed58bf62a1140ee6dc7417b6a0a97ecc6 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 12:11:03 +0100 Subject: sqlbox: Close database connection --- sqlbox/view.php | 1 + 1 file changed, 1 insertion(+) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index dd20fb9..316489a 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -101,6 +101,7 @@ if (isset($data->query)) { echo ""; } echo "
".pg_field_name($result, $i)."
"; + pg_close($db); } // Finish the page -- cgit From 199d95ae1f065a3a252af3d4aad9bc3d778aedd3 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 12:22:02 +0100 Subject: Change output box border style. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 316489a..b5d613e 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,7 +88,7 @@ if (isset($data->query)) { if (!$result) error("Query failed!"); - echo ""; + echo "
"; $n = pg_num_fields($result); for ($i = 0; $i < $n; $i++) { echo ""; -- cgit From e6d9384cfa1af9c69636b4bc6bf1108327ea3085 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 13:06:06 +0100 Subject: sqlbox: Add prefixes to form Or it clashes with moodle search box. --- sqlbox/view.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index b5d613e..1158d7b 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,13 +78,13 @@ $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); $data = $form->get_data(); -echo $OUTPUT->heading('SQL Query: '.$data->query); -if (isset($data->query)) { +echo $OUTPUT->heading('SQL Query: '.$data->sqlbox_query); +if (isset($data->sqlbox_query)) { $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); if (!db) error("Failed to connect to sqlbox db"); - $result = pg_query($db, $data->query); + $result = pg_query($db, $data->sqlbox_query); if (!$result) error("Query failed!"); -- cgit From 0b3e94f02d5c4cfcfb93a90896881652eceafc55 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 13:34:09 +0100 Subject: Add additional error string from database. --- sqlbox/view.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 1158d7b..d334835 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -84,7 +84,10 @@ if (isset($data->sqlbox_query)) { if (!db) error("Failed to connect to sqlbox db"); - $result = pg_query($db, $data->sqlbox_query); +// $result = pg_query($db, $data->sqlbox_query); + $result = pg_send_query($db, $data->sqlbox_query); + $result = pg_get_result($db); + echo pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); if (!$result) error("Query failed!"); -- cgit From b27fcb3087ecac1b61cff59d35bdab7c7d5ded09 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 14:54:59 +0100 Subject: Revert "Add additional error string from database." This reverts commit 0b3e94f02d5c4cfcfb93a90896881652eceafc55. --- sqlbox/view.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index d334835..1158d7b 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -84,10 +84,7 @@ if (isset($data->sqlbox_query)) { if (!db) error("Failed to connect to sqlbox db"); -// $result = pg_query($db, $data->sqlbox_query); - $result = pg_send_query($db, $data->sqlbox_query); - $result = pg_get_result($db); - echo pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); + $result = pg_query($db, $data->sqlbox_query); if (!$result) error("Query failed!"); -- cgit From bbee0f79be6080ba589b043e68321c17dd295d65 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 14:55:30 +0100 Subject: sqlbox: Display error message --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 1158d7b..b45924b 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -86,7 +86,7 @@ if (isset($data->sqlbox_query)) { $result = pg_query($db, $data->sqlbox_query); if (!$result) - error("Query failed!"); + error("Query failed: ".pg_last_error($db)); echo "
".pg_field_name($result, $i)."
"; $n = pg_num_fields($result); -- cgit From 2a14d4ae5af7dd2b08e7a16b155d45cebd3ca763 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 12:07:35 +0100 Subject: sqlbox: User html_output::table to show query result ..instead of own table code. --- sqlbox/view.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index b45924b..2169ab0 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,19 +88,16 @@ if (isset($data->sqlbox_query)) { if (!$result) error("Query failed: ".pg_last_error($db)); - echo "
"; + $table = new html_table(); $n = pg_num_fields($result); - for ($i = 0; $i < $n; $i++) { - echo ""; - } - while($row=pg_fetch_row($result)){ - echo ""; - foreach($row as $val) { - echo ""; - } - echo ""; - } - echo "
".pg_field_name($result, $i)."
$val
"; + 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; + + echo html_writer::table($table); + pg_close($db); } -- cgit From 1e7e0ed272a3fa984241314dc01a871d3fa03c35 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 16:07:25 +0100 Subject: sqlbox: Remove unneeded brackets in class initialization --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlbox/view.php') diff --git a/sqlbox/view.php b/sqlbox/view.php index 2169ab0..5f0e4a0 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,7 +88,7 @@ if (isset($data->sqlbox_query)) { if (!$result) error("Query failed: ".pg_last_error($db)); - $table = new html_table(); + $table = new html_table; $n = pg_num_fields($result); for ($i = 0; $i < $n; $i++) $table->head[] = pg_field_name($result, $i); -- cgit