From bf0001ad7dc5aabbf818d4e6235a5eb03ad090d6 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 10 Feb 2012 13:13:19 -0500 Subject: [PATCH] Added get_system_tables function to db classes, added _manip subclasses to mysql and pgsql --- src/common/db_pdo.php | 15 +++++++----- src/databases/firebird.php | 25 +++++++++++++++++++- src/databases/mysql.php | 14 ++++++++++++ src/databases/odbc.php | 11 +++++++++ src/databases/pgsql.php | 42 ++++++++++++++++++++++++++++++++-- src/databases/sqlite.php | 5 ++++ src/windows/add_db.php | 3 ++- tests/test_dbs/test_sqlite.db | Bin 4096 -> 4096 bytes 8 files changed, 105 insertions(+), 10 deletions(-) diff --git a/src/common/db_pdo.php b/src/common/db_pdo.php index 2240a70..928ea04 100644 --- a/src/common/db_pdo.php +++ b/src/common/db_pdo.php @@ -26,12 +26,6 @@ abstract class DB_PDO extends PDO { function __construct($dsn, $username=NULL, $password=NULL, $driver_options=array()) { parent::__construct($dsn, $username, $password, $driver_options); - - if(__CLASS__ !== "DB_PDO") - { - $class = __CLASS__.'_manip'; - $this->manip = new $class; - } } // ------------------------------------------------------------------------- @@ -142,6 +136,15 @@ abstract class DB_PDO extends PDO { * @return int */ abstract function num_rows(); + + /** + * Retreives an array of non-user-created tables for + * the connection/database + * + * @return array + */ + abstract function get_system_tables(); + } // ------------------------------------------------------------------------- diff --git a/src/databases/firebird.php b/src/databases/firebird.php index ce3944c..c0b37f2 100644 --- a/src/databases/firebird.php +++ b/src/databases/firebird.php @@ -132,7 +132,7 @@ class firebird { /** * List tables for the current database * - * @return mixed + * @return array */ function get_tables() { @@ -151,6 +151,29 @@ class firebird { return $tables; } + /** + * List system tables for the current database + * + * @return array + */ + function get_system_tables() + { + $sql='SELECT RDB$RELATION_NAME as "rn" FROM "RDB$RELATIONS" + WHERE "rn" LIKE \'RDB$\' + OR "rn" LIKE \'RDB$\''; + + $this->statement = $this->query($sql); + + $tables = array(); + + while($row = $this->fetch(PDO::FETCH_ASSOC)) + { + $tables[] = $row['RDB$RELATION_NAME']; + } + + return $tables; + } + /** * Return the number of rows affected by the previous query * diff --git a/src/databases/mysql.php b/src/databases/mysql.php index 0ff1cca..4e37a7a 100644 --- a/src/databases/mysql.php +++ b/src/databases/mysql.php @@ -35,6 +35,9 @@ class MySQL extends DB_PDO { $options); parent::__construct("mysql:$dsn", $username, $password, $options); + + $class = __CLASS__.'_manip'; + $this->manip = new $class; } /** @@ -69,6 +72,17 @@ class MySQL extends DB_PDO { return $res->fetchAll(PDO::FETCH_ASSOC); } + /** + * Returns system tables for the current database + * + * @return array + */ + function get_system_tables() + { + //MySQL doesn't have system tables + return array(); + } + /** * Return the number of rows returned for a SELECT query * diff --git a/src/databases/odbc.php b/src/databases/odbc.php index f6fdee7..5d2125e 100644 --- a/src/databases/odbc.php +++ b/src/databases/odbc.php @@ -37,6 +37,17 @@ class ODBC extends DB_PDO { return FALSE; } + /** + * List system tables for the current database/connection + * + * @return array + */ + function get_system_tables() + { + //No way of determining for ODBC + return array(); + } + /** * Empty the current database * diff --git a/src/databases/pgsql.php b/src/databases/pgsql.php index 9e76ea6..20d73eb 100644 --- a/src/databases/pgsql.php +++ b/src/databases/pgsql.php @@ -30,6 +30,10 @@ class pgSQL extends DB_PDO { function __construct($dsn, $username=null, $password=null, $options=array()) { parent::__construct("pgsql:$dsn", $username, $password, $options); + + //Get db manip class + $class = __CLASS__.'_manip'; + $this->manip = new $class; } /** @@ -71,9 +75,43 @@ class pgSQL extends DB_PDO { $res = $this->query($sql); - $dbs = $res->fetchAll(PDO::FETCH_ASSOC); + $tables = $res->fetchAll(PDO::FETCH_ASSOC); - return $dbs; + return $tables; + } + + /** + * Get the list of system tables + * + * @return array + */ + function get_system_tables() + { + $sql = 'SELECT "tablename" FROM "pg_tables" + WHERE "tablename" LIKE \'pg\_%\' + OR "tablename" LIKE \'sql\%\''; + + $res = $this->query($sql); + + $tables = $res->fetchAll(PDO::FETCH_ASSOC); + + return $tables; + + } + + /** + * Get a list of schemas, either for the current connection, or + * for the current datbase, if specified. + * + * @param string $database="" + * @return array + */ + function get_schemas($database="") + { + $sql = 'SELECT '; + + $res = $this->query($sql); + $schemas = $res->fetchAll(PDO::FETCH_ASSOC); } /** diff --git a/src/databases/sqlite.php b/src/databases/sqlite.php index 381b970..5842da8 100644 --- a/src/databases/sqlite.php +++ b/src/databases/sqlite.php @@ -65,6 +65,11 @@ class SQLite extends DB_PDO { return $tables; } + function get_system_tables() + { + + } + /** * Return the number of rows returned for a SELECT query * diff --git a/src/windows/add_db.php b/src/windows/add_db.php index 6d04cac..ea493cb 100644 --- a/src/windows/add_db.php +++ b/src/windows/add_db.php @@ -93,7 +93,8 @@ class Add_DB extends GtkWindow { { $add_button = new GtkButton(); $add_button->set_label("Add Connnection"); - $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, Gtk::ICON_SIZE_SMALL_TOOLBAR)); + $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, + Gtk::ICON_SIZE_SMALL_TOOLBAR)); $table->attach($add_button, 0, 3, ++$y1, ++$y2); $add_button->connect_simple("clicked", array($this, 'db_add')); } diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index 6efd8d29fc4bc1edbf852ca3eac19fecf079319c..48a9d0cffa5abbd3e40ce6436e3671b7eb559063 100755 GIT binary patch delta 53 zcmZorXi%6SEvU-Cz`z2;%s|Wp#Htf@j9FC~bRQ{gO!>kzu`zJ-O6G8m%?d2fnI}$= F1ONz+48i~a delta 127 zcmZorXi%6SEvU@Ez`z2;%s|Wp#L5$Oj9HZ#bRWrYO!>kTsI1JGUy_)VlbT$Vnplz= zUy@o}g2ZHT4svx2aa9O$bn