diff options
Diffstat (limited to 'system/database/drivers')
-rw-r--r-- | system/database/drivers/mssql/mssql_driver.php | 28 | ||||
-rw-r--r-- | system/database/drivers/mssql/mssql_utility.php | 28 | ||||
-rw-r--r-- | system/database/drivers/mysql/mysql_driver.php | 28 | ||||
-rw-r--r-- | system/database/drivers/mysql/mysql_utility.php | 95 | ||||
-rw-r--r-- | system/database/drivers/mysqli/mysqli_driver.php | 30 | ||||
-rw-r--r-- | system/database/drivers/mysqli/mysqli_utility.php | 28 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_driver.php | 28 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_utility.php | 28 | ||||
-rw-r--r-- | system/database/drivers/odbc/odbc_driver.php | 33 | ||||
-rw-r--r-- | system/database/drivers/odbc/odbc_utility.php | 53 | ||||
-rw-r--r-- | system/database/drivers/postgre/postgre_driver.php | 28 | ||||
-rw-r--r-- | system/database/drivers/postgre/postgre_utility.php | 28 | ||||
-rw-r--r-- | system/database/drivers/sqlite/sqlite_driver.php | 39 | ||||
-rw-r--r-- | system/database/drivers/sqlite/sqlite_utility.php | 46 |
14 files changed, 240 insertions, 280 deletions
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 3f5e53345..8b82ee314 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -262,6 +262,34 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** * List columnn query * * Generates a platform-specific query string so that the column names can be fetched diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 96b8180b8..ad13167cd 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -54,34 +54,6 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * @access private diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 792e023a8..ecab648d4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -292,6 +292,34 @@ class CI_DB_mysql_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index f43299382..a81c915f6 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -53,34 +53,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * @access private @@ -132,50 +104,22 @@ class CI_DB_mysql_utility extends CI_DB_utility { * @param array Any preferences * @return mixed */ - function _export($params = array()) + function _backup($params = array()) { - // Set up our default preferences - $prefs = array( - 'tables' => array(), - 'ignore' => array(), - 'format' => 'gzip', - 'action' => 'download', // download, archive, echo, return - 'filename' => date('Y-m-d-H:i', time()), - 'filepath' => '', - 'add_drop' => TRUE, - 'add_insert' => TRUE, - 'newline' => "\n" - ); - - // Did the user submit any preference overrides? If so set them.... - if (count($params) > 0) + if (count($params) == 0) { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } + return FALSE; } // Extract the prefs for simplicity - extract($prefs); - - // Are we backing up a complete database or individual tables? - if (count($tables) == 0) - { - $tables = $this->list_tables(); - } - - // Start buffering the output - ob_start(); + extract($params); // Build the output - foreach ($tables as $table) + $output = ''; + foreach ((array)$tables as $table) { // Is the table in the "ignore" list? - if (in_array($table, $ignore)) + if (in_array($table, (array)$ignore, TRUE)) { continue; } @@ -190,11 +134,11 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Write out the table schema - echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; if ($add_drop == TRUE) { - echo 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; } $i = 0; @@ -203,7 +147,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { { if ($i++ % 2) { - echo $val.';'.$newline.$newline; + $output .= $val.';'.$newline.$newline; } } @@ -270,27 +214,16 @@ class CI_DB_mysql_utility extends CI_DB_utility { } $val_str = preg_replace( "/, $/" , "" , $val_str); - - if ($action == 'echo') - { - $val_str = htmlspecialchars($val_str); - } - + // Build the INSERT string - echo 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } - - - $buffer = ob_get_contents(); - @ob_end_clean(); - - echo $buffer; - + $output .= $newline.$newline; } - + return $output; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b158cfefe..a2c380355 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -284,7 +284,35 @@ class CI_DB_mysqli_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 754ffbda2..f5b98b11f 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -53,34 +53,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * @access private diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bc0a100c2..b43b4c41f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -399,6 +399,34 @@ class CI_DB_oci8_driver extends CI_DB { return $row->NUMROWS; } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT TABLE_NAME FROM ALL_TABLES"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 4d267dc6a..b6503de63 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -54,34 +54,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * @access private diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index cdde2e2ea..0f002cc1b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -259,6 +259,39 @@ class CI_DB_odbc_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 3d420f69d..6d0fb79f1 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -36,9 +36,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "create database" command since it's // designed to connect to an existing database - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -56,9 +56,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "drop database" command since it's // designed to connect to an existing database - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -66,39 +66,6 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * @access private @@ -107,9 +74,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _drop_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -128,9 +95,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _optimize_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -149,9 +116,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _repair_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 026284118..f14395638 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -286,6 +286,34 @@ class CI_DB_postgre_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7b51c3fe7..46c98cc7d 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -54,34 +54,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * @access private diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 45dd7a892..f57c4b8c8 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -278,7 +278,44 @@ class CI_DB_sqlite_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - + + // -------------------------------------------------------------------- + + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ae241db87..801660d94 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -52,9 +52,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility { { if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unable_to_drop'); + return $this->db->display_error('db_unable_to_drop'); } return FALSE; } @@ -64,44 +64,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** * Drop Table * * Unsupported feature in SQLite @@ -111,9 +73,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _drop_table($table) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return array(); } |