diff --git a/index.php b/index.php index f50c43d..6c8fd0b 100644 --- a/index.php +++ b/index.php @@ -26,6 +26,9 @@ error_reporting(-1 & ~(E_STRICT)); // Set the stupid timezone so PHP shuts up. date_default_timezone_set('GMT'); +// Don't set an arbitary memory limit! +ini_set('memory_limit', -1); + // Set the current directory as the base for included files define('BASE_DIR', dirname(__FILE__).'/sys'); define('SETTINGS_DIR', dirname(__FILE__)); diff --git a/sys/common/functions.php b/sys/common/functions.php index 96f0319..6ab1fef 100644 --- a/sys/common/functions.php +++ b/sys/common/functions.php @@ -143,4 +143,23 @@ function about() $dlg->destroy(); } +/** + * Filter out db rows into one array + * + * @param array $array + * @param mixed $index + * @return array + */ +function db_filter($array, $index) +{ + $new_array = array(); + + foreach($array as $a) + { + $new_array[] = $a[$index]; + } + + return $new_array; +} + // End of functions.php \ No newline at end of file diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index cd0b408..bb4fc64 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -212,6 +212,13 @@ abstract class DB_PDO extends PDO { */ abstract public function get_dbs(); + /** + * Return list of views for the current database + * + * @return array + */ + abstract public function get_views(); + /** * Empty the passed table * diff --git a/sys/db/drivers/firebird.php b/sys/db/drivers/firebird.php index 3c40583..e1ada08 100644 --- a/sys/db/drivers/firebird.php +++ b/sys/db/drivers/firebird.php @@ -151,6 +151,19 @@ SQL; // -------------------------------------------------------------------------- + /** + * Get list of views for the current database + * + * @return array + */ + public function get_views() + { + // @todo Implement + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Not applicable to firebird * diff --git a/sys/db/drivers/mysql.php b/sys/db/drivers/mysql.php index 9b58009..bead5e4 100644 --- a/sys/db/drivers/mysql.php +++ b/sys/db/drivers/mysql.php @@ -56,17 +56,8 @@ class MySQL extends DB_PDO { */ public function get_dbs() { - $res = $this->query("SHOW DATABASES"); - $vals = array_values($res->fetchAll(PDO::FETCH_ASSOC)); - - $return = array(); - - foreach($vals as $v) - { - $return[] = $v['Database']; - } - - return $return; + $res = $this->query("SHOW DATABASES WHERE `Database` !='information_schema'"); + return db_filter(array_values($res->fetchAll(PDO::FETCH_ASSOC)), 'Database'); } // -------------------------------------------------------------------------- @@ -78,17 +69,21 @@ class MySQL extends DB_PDO { */ public function get_tables() { - $res = $this->query("SHOW TABLES"); + $res = $this->query('SHOW TABLES'); + return db_filter($res->fetchAll(PDO::FETCH_NUM), 0); + } - $tables = array(); - $rows = $res->fetchAll(PDO::FETCH_NUM); + // -------------------------------------------------------------------------- - foreach($rows as $r) - { - $tables[] = $r[0]; - } - - return $tables; + /** + * Get list of views for the current database + * + * @return array + */ + public function get_views() + { + $res = $this->query('SELECT `table_name` FROM `information_schema`.`views`'); + return db_filter($res->fetchAll(PDO::FETCH_NUM), 'table_name'); } // -------------------------------------------------------------------------- diff --git a/sys/db/drivers/odbc.php b/sys/db/drivers/odbc.php index 6b1cfb2..674ac8f 100644 --- a/sys/db/drivers/odbc.php +++ b/sys/db/drivers/odbc.php @@ -45,7 +45,7 @@ class ODBC extends DB_PDO { // -------------------------------------------------------------------------- /** - * Not applicable to firebird + * Not applicable to ODBC * * @return FALSE */ @@ -56,6 +56,18 @@ class ODBC extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Not applicable to ODBC + * + * @return FALSE + */ + public function get_views() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * List system tables for the current database/connection * diff --git a/sys/db/drivers/pgsql.php b/sys/db/drivers/pgsql.php index c7f1ae3..52e60e9 100644 --- a/sys/db/drivers/pgsql.php +++ b/sys/db/drivers/pgsql.php @@ -66,9 +66,7 @@ SQL; $res = $this->query($sql); - $dbs = $res->fetchAll(PDO::FETCH_ASSOC); - - return $dbs; + return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'datname'); } // -------------------------------------------------------------------------- @@ -88,16 +86,8 @@ SQL; $res = $this->query($sql); - $tables = $res->fetchAll(PDO::FETCH_ASSOC); + return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'tablename'); - $good_tables = array(); - - foreach($tables as $t) - { - $good_tables[] = $t['tablename']; - } - - return $good_tables; } // -------------------------------------------------------------------------- @@ -117,10 +107,7 @@ SQL; $res = $this->query($sql); - $tables = $res->fetchAll(PDO::FETCH_ASSOC); - - return $tables; - + return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'tablename'); } // -------------------------------------------------------------------------- @@ -170,9 +157,8 @@ SQL; $res = $this->query($sql); - $views = $res->fetchAll(PDO::FETCH_ASSOC); - return $views; + return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'viewname'); } // -------------------------------------------------------------------------- diff --git a/sys/db/drivers/sqlite.php b/sys/db/drivers/sqlite.php index 92c60de..11931c1 100644 --- a/sys/db/drivers/sqlite.php +++ b/sys/db/drivers/sqlite.php @@ -83,7 +83,7 @@ SQL; // -------------------------------------------------------------------------- /** - * Not applicable to firebird + * Not applicable to SQLite * * @return FALSE */ @@ -94,6 +94,19 @@ SQL; // -------------------------------------------------------------------------- + /** + * Get list of views for the current database + * + * @return array + */ + public function get_views() + { + // @todo Implement + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * List system tables for the current database * diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index ac77ec1..6a81718 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -89,7 +89,7 @@ class DB_tabs extends GTKNotebook { $db_model = $dbs->get_model(); $db_data = $conn->get_dbs(); - if($db_data) + if($db_data !== FALSE) { foreach($db_data as $d) { @@ -115,7 +115,6 @@ class DB_tabs extends GTKNotebook { foreach($table_data as $t) { $table_model->append(null, array($t)); - //$table_model->set($iter, 0, $t); } $cell_renderer = new GtkCellRendererText(); @@ -127,7 +126,22 @@ class DB_tabs extends GTKNotebook { // 'Views' Tab { - + $views = new Data_grid(); + $view_model = $views->get_model(); + $view_data = $conn->get_views(); + + if ($view_data !== FALSE) + { + foreach($view_data as $v) + { + $view_model->append(null, array($v)); + } + + $cell_renderer = new GtkCellRendererText(); + $views->insert_column_with_data_func(0, 'View Name', $cell_renderer, array(self::$instance, 'add_data_col')); + + self::$instance->add_tab('Views', $views); + } } @@ -149,8 +163,16 @@ class DB_tabs extends GTKNotebook { */ public function add_data_col($col, $cell, $model, $iter, $i=0) { - $col->set_visible(TRUE); $data = $model->get_value($iter, $i); + + if (empty($data)) + { + return; + } + + print_r($data); + + $col->set_visible(TRUE); $cell->set_property('text', $data); }