diff --git a/index.php b/index.php index 6c8fd0b..9398db4 100644 --- a/index.php +++ b/index.php @@ -107,20 +107,18 @@ foreach(pdo_drivers() as $d) continue; } - $file = "{$path}{$d}.php"; + $dir = "{$path}{$d}"; - if(is_file($file)) + if(is_dir($dir)) { - require_once("{$path}{$d}.php"); - require_once("{$path}{$d}_sql.php"); + array_map('do_include', glob($dir.'/*.php')); } } // Load Firebird if there is support if(function_exists('fbird_connect')) { - require_once("{$path}firebird.php"); - require_once("{$path}firebird_sql.php"); + array_map('do_include', glob($path.'*.php')); } // -------------------------------------------------------------------------- diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index 7ab4b84..acd4428 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -294,5 +294,13 @@ abstract class DB_PDO extends PDO { * @return string */ abstract public function backup_data(); + + /** + * Connect to a different database + * + * @param string $name + * @return void + */ + abstract public function switch_db($name); } // End of db_pdo.php \ No newline at end of file diff --git a/sys/db/drivers/firebird/firebird.php b/sys/db/drivers/firebird/firebird.php index 285c1cc..c5ebbe4 100644 --- a/sys/db/drivers/firebird/firebird.php +++ b/sys/db/drivers/firebird/firebird.php @@ -56,6 +56,16 @@ class firebird extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Doesn't apply to Firebird + */ + public function switch_db($name) + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Empty a database table * diff --git a/sys/db/drivers/mysql/mysql.php b/sys/db/drivers/mysql/mysql.php index be4487b..9472c6f 100644 --- a/sys/db/drivers/mysql/mysql.php +++ b/sys/db/drivers/mysql/mysql.php @@ -37,6 +37,19 @@ class MySQL extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Connect to a different database + * + * @param string $name + */ + public function switch_db($name) + { + // @todo Implement + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Empty a table * diff --git a/sys/db/drivers/odbc/odbc.php b/sys/db/drivers/odbc/odbc.php index 0484e2c..eb47fee 100644 --- a/sys/db/drivers/odbc/odbc.php +++ b/sys/db/drivers/odbc/odbc.php @@ -31,6 +31,16 @@ class ODBC extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Doesn't apply to ODBC + */ + public function switch_db($name) + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * List tables for the current database * diff --git a/sys/db/drivers/pgsql/pgsql.php b/sys/db/drivers/pgsql/pgsql.php index 681732f..3d52b70 100644 --- a/sys/db/drivers/pgsql/pgsql.php +++ b/sys/db/drivers/pgsql/pgsql.php @@ -38,6 +38,19 @@ class pgSQL extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Connect to a different database + * + * @param string $name + */ + public function switch_db($name) + { + // @todo Implement + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Empty a table * diff --git a/sys/db/drivers/sqlite/sqlite.php b/sys/db/drivers/sqlite/sqlite.php index 45d2251..a7850ea 100644 --- a/sys/db/drivers/sqlite/sqlite.php +++ b/sys/db/drivers/sqlite/sqlite.php @@ -37,6 +37,16 @@ class SQLite extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Doesn't apply to sqlite + */ + public function switch_db($name) + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Empty a table * diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index 54e7142..d1ea52c 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -82,7 +82,9 @@ class DB_tabs extends GTKNotebook { // 'Databases' Tab { - self::_add_tab($conn, 'Databases', 'Db Name', 'get_dbs'); + self::_add_tab($conn, 'Databases', 'Db Name', 'get_dbs', array(), array( + 'row-activated' => array(self::$instance, '_switch_db'), + )); } // 'Schemas' Tab @@ -179,7 +181,7 @@ class DB_tabs extends GTKNotebook { * @param string $method * @return void */ - private static function _add_tab(&$conn, $tab_name, $col_name, $method, $params=array()) + private static function _add_tab(&$conn, $tab_name, $col_name, $method, $params=array(), $events=array()) { $tab = new Data_Grid(); $tab_model = $tab->get_model(); @@ -196,6 +198,14 @@ class DB_tabs extends GTKNotebook { $cell_renderer = new GtkCellRendererText(); $tab->insert_column_with_data_func(0, $col_name, $cell_renderer, array(self::$instance, 'add_data_col')); + if ( ! empty($events)) + { + foreach($events as $name => $method) + { + $tab->connect($name, $method); + } + } + self::$instance->add_tab($tab_name, $tab); } @@ -260,5 +270,22 @@ class DB_tabs extends GTKNotebook { return; } + + /** + * Connects to a different database than the one currently in use + * + * @param type $view + * @param type $path + * @param type $column + * @param type $data + */ + public function _switch_db($view, $path, $column, $data=array()) + { + // Get the selected database + $new_db = $view->get(0); + + + + } } // End of db_tabs.php diff --git a/tests/index.php b/tests/index.php index 586ea7c..99adbd9 100644 --- a/tests/index.php +++ b/tests/index.php @@ -60,8 +60,7 @@ foreach(pdo_drivers() as $d) if(is_file($src_file)) { - require_once("{$src_path}{$d}.php"); - require_once("{$src_path}{$d}_sql.php"); + array_map('do_include', glob($src_path.$d.'/*.php')); require_once("{$test_path}{$d}.php"); require_once("{$test_path}{$d}-qb.php"); } @@ -70,8 +69,7 @@ foreach(pdo_drivers() as $d) // Load Firebird if there is support if(function_exists('fbird_connect')) { - require_once("{$src_path}firebird.php"); - require_once("{$src_path}firebird_sql.php"); + array_map('do_include', glob($src_path.'firebird/*.php')); require_once("{$test_path}firebird.php"); require_once("{$test_path}firebird-qb.php"); } \ No newline at end of file