summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-09-30 21:24:45 +0200
committeradmin <devnull@localhost>2006-09-30 21:24:45 +0200
commit3dd978f680076be842bfcb5c9e2cbf35b926373b (patch)
treee4cd05724744ee70eb497118692581e750539548 /system/database
parent3ed8c51254a5b26d951fa675802fcf69adf9638e (diff)
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_driver.php101
-rw-r--r--system/database/DB_utility.php310
-rw-r--r--system/database/drivers/mssql/mssql_driver.php28
-rw-r--r--system/database/drivers/mssql/mssql_utility.php28
-rw-r--r--system/database/drivers/mysql/mysql_driver.php28
-rw-r--r--system/database/drivers/mysql/mysql_utility.php95
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php30
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php28
-rw-r--r--system/database/drivers/oci8/oci8_driver.php28
-rw-r--r--system/database/drivers/oci8/oci8_utility.php28
-rw-r--r--system/database/drivers/odbc/odbc_driver.php33
-rw-r--r--system/database/drivers/odbc/odbc_utility.php53
-rw-r--r--system/database/drivers/postgre/postgre_driver.php28
-rw-r--r--system/database/drivers/postgre/postgre_utility.php28
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php39
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php46
16 files changed, 561 insertions, 370 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 275d51c53..5102cc74c 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -555,6 +555,95 @@ class CI_DB_driver {
// --------------------------------------------------------------------
+ // --------------------------------------------------------------------
+
+ /**
+ * List databases
+ *
+ * @access public
+ * @return bool
+ */
+ function list_databases()
+ {
+ // Is there a cached result?
+ if (isset($this->cache['db_names']))
+ {
+ return $this->cache['db_names'];
+ }
+
+ $query = $this->query($this->_list_database());
+ $dbs = array();
+ if ($query->num_rows() > 0)
+ {
+ foreach ($query->result_array() as $row)
+ {
+ $dbs[] = current($row);
+ }
+ }
+
+ return $this->cache['db_names'] =& $dbs;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Returns an array of table names
+ *
+ * @access public
+ * @return array
+ */
+ function list_tables()
+ {
+ // Is there a cached result?
+ if (isset($this->cache['table_names']))
+ {
+ return $this->cache['table_names'];
+ }
+
+ if (FALSE === ($sql = $this->_list_tables()))
+ {
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_unsupported_function');
+ }
+ return FALSE;
+ }
+
+ $retval = array();
+ $query = $this->query($sql);
+
+ if ($query->num_rows() > 0)
+ {
+ foreach($query->result_array() as $row)
+ {
+ if (isset($row['TABLE_NAME']))
+ {
+ $retval[] = $row['TABLE_NAME'];
+ }
+ else
+ {
+ $retval[] = array_shift($row);
+ }
+ }
+ }
+
+ return $this->cache['table_names'] =& $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Determine if a particular table exists
+ * @access public
+ * @return boolean
+ */
+ function table_exists($table_name)
+ {
+ return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Fetch MySQL Field Names
*
@@ -562,7 +651,7 @@ class CI_DB_driver {
* @param string the table name
* @return array
*/
- function field_names($table = '')
+ function list_fields($table = '')
{
// Is there a cached result?
if (isset($this->cache['field_names'][$table]))
@@ -605,6 +694,16 @@ class CI_DB_driver {
return $this->cache['field_names'][$table] =& $retval;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * DEPRECATED - use list_fields()
+ */
+ function field_names($table = '')
+ {
+ return $this->list_fields($table);
+ }
// --------------------------------------------------------------------
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index ff9407ebd..dc56d6524 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -87,93 +87,6 @@ class CI_DB_utility {
// --------------------------------------------------------------------
/**
- * List databases
- *
- * @access public
- * @return bool
- */
- function list_databases()
- {
- // Is there a cached result?
- if (isset($this->cache['db_names']))
- {
- return $this->cache['db_names'];
- }
-
- $query = $this->db->query($this->_list_database());
- $dbs = array();
- if ($query->num_rows() > 0)
- {
- foreach ($query->result_array() as $row)
- {
- $dbs[] = current($row);
- }
- }
-
- return $this->cache['db_names'] =& $dbs;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Returns an array of table names
- *
- * @access public
- * @return array
- */
- function list_tables()
- {
- // Is there a cached result?
- if (isset($this->cache['table_names']))
- {
- return $this->cache['table_names'];
- }
-
- if (FALSE === ($sql = $this->_list_tables()))
- {
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsupported_function');
- }
- return FALSE;
- }
-
- $retval = array();
- $query = $this->db->query($sql);
-
- if ($query->num_rows() > 0)
- {
- foreach($query->result_array() as $row)
- {
- if (isset($row['TABLE_NAME']))
- {
- $retval[] = $row['TABLE_NAME'];
- }
- else
- {
- $retval[] = array_shift($row);
- }
- }
- }
-
- return $this->cache['table_names'] =& $retval;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Determine if a particular table exists
- * @access public
- * @return boolean
- */
- function table_exists($table_name)
- {
- return ( ! in_array($this->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Optimize Table
*
* @access public
@@ -372,12 +285,231 @@ class CI_DB_utility {
* @access public
* @return void
*/
- function export()
+ function backup($params = array())
{
- // The individual driver overloads this method
+ // If the parameters have not been submitted as an
+ // array then we know that it is simply the table
+ // name, which is a valid short cut.
+ if (is_string($params))
+ {
+ $params = array('tables' => $params);
+ }
+
+ // ------------------------------------------------------
+
+ // Set up our default preferences
+ $prefs = array(
+ 'tables' => array(),
+ 'ignore' => array(),
+ 'format' => 'gzip', // gzip, zip, txt
+ 'action' => 'download', // download, archive, echo, return
+ 'filename' => '',
+ 'filepath' => '',
+ 'add_drop' => TRUE,
+ 'add_insert' => TRUE,
+ 'newline' => "\n"
+ );
+
+ // Did the user submit any preferences? If so set them....
+ if (count($params) > 0)
+ {
+ foreach ($prefs as $key => $val)
+ {
+ if (isset($params[$key]))
+ {
+ $prefs[$key] = $params[$key];
+ }
+ }
+ }
+
+ // ------------------------------------------------------
+
+ // Are we backing up a complete database or individual tables?
+ // If no table names were submitted we'll fetch the entire table list
+ if (count($prefs['tables']) == 0)
+ {
+ $prefs['tables'] = $this->list_tables();
+ }
+
+ // ------------------------------------------------------
+
+ // Validate the format
+ if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
+ {
+ $prefs['format'] = 'txt';
+ }
+
+ // ------------------------------------------------------
+
+ // Is the encoder supported? If not, we'll either issue an
+ // error or use plain text depending on the debug settings
+ if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode'))
+ OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress')))
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_compression');
+ }
+
+ $prefs['format'] = 'txt';
+ }
+
+ // ------------------------------------------------------
+
+ // Set the filename if not provided
+ if ($prefs['filename'] == '')
+ {
+ $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database;
+ $prefs['filename'] .= '_'.date('Y-m-d_H-i', time());
+ }
+
+ // ------------------------------------------------------
+
+ // If we are archiving the export, does this filepath exist
+ // and resolve to a writable directory
+ if ($prefs['action'] == 'archive')
+ {
+ if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath']))
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_filepath_error');
+ }
+
+ $prefs['action'] = 'download';
+ }
+ }
+
+ // ------------------------------------------------------
+
+ // Are we returning the backup data? If so, we're done...
+ if ($prefs['action'] == 'return')
+ {
+ return $this->_backup($prefs);
+ }
+
+ // ------------------------------------------------------
+
+ // Are we echoing the backup? If so, format the data and spit it at the screen...
+ if ($prefs['action'] == 'echo')
+ {
+ echo '<pre>';
+ echo htmlspecialchars($this->_backup($prefs));
+ echo '</pre>';
+
+ return TRUE;
+ }
+
+ // ------------------------------------------------------
+
+ // Are we archiving the data to the server?
+ if ($prefs['action'] == 'archive')
+ {
+ // Make sure the filepath has a trailing slash
+ if (ereg("/$", $prefs['filepath']) === FALSE)
+ {
+ $prefs['filepath'] .= '/';
+ }
+
+ // Assemble the path and tack on the file extension
+ $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql');
+ $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']];
+
+ // Load the file helper
+ $obj =& get_instance();
+ $obj->load->helper('file');
+
+ // Write the file based on type
+ switch ($prefs['format'])
+ {
+ case 'gzip' :
+ write_file($path, gzencode($this->_backup($prefs)));
+ return TRUE;
+ break;
+ case 'txt' :
+ write_file($path, $this->_backup($prefs));
+ return TRUE;
+ break;
+ default :
+ require BASEPATH.'libraries/Zip.php';
+ $zip = new Zip;
+ $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql');
+ write_file($path, $zip->output_zipfile());
+ return TRUE;
+ break;
+ }
+
+ }
+
+ // ------------------------------------------------------
+
+ // Set the mime type used in the server header
+ switch ($prefs['format'])
+ {
+ case 'zip' : $mime = 'application/x-zip';
+ break;
+ case 'gzip' : $mime = 'application/x-gzip';
+ break;
+ default :
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA"))
+ {
+ $mime = 'application/octetstream';
+ }
+ else
+ {
+ $mime = 'application/octet-stream';
+ }
+ break;
+ }
+
+ // Grab the super object
+ $obj =& get_instance();
+
+ // Remap the file extensions
+ $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql');
+
+ // Send headers
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
+ {
+ $obj->output->set_header('Content-Type: '.$mime);
+ $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"');
+ $obj->output->set_header('Expires: 0');
+ $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ $obj->output->set_header('Pragma: public');
+ }
+ else
+ {
+ $obj->output->set_header('Content-Type: '.$mime);
+ $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"');
+ $obj->output->set_header('Expires: 0');
+ $obj->output->set_header('Pragma: no-cache');
+ }
+
+
+ // Write the file based on type
+ switch ($prefs['format'])
+ {
+ case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs)));
+ break;
+ case 'txt' : $obj->output->set_output($this->_backup($prefs));
+ break;
+ default :
+ require BASEPATH.'libraries/Zip.php';
+
+ $zip = new Zip;
+ $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql');
+ $obj->output->set_output($zip->output_zipfile());
+ break;
+ }
+
+ return TRUE;
}
+
+
+
+
}
?> \ No newline at end of file
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();
}