summaryrefslogtreecommitdiffstats
path: root/system/database/DB_utility.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/DB_utility.php')
-rw-r--r--system/database/DB_utility.php128
1 files changed, 64 insertions, 64 deletions
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 642a004bd..02c921834 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -37,6 +37,11 @@ abstract class CI_DB_utility extends CI_DB_forge {
public $db;
public $data_cache = array();
+ // Platform specific SQL strings
+ // Just setting those defaults to FALSE as they are mostly MySQL-specific
+ protected $_optimize_table = FALSE;
+ protected $_repair_table = FALSE;
+
public function __construct()
{
// Assign the main database object to $this->db
@@ -50,7 +55,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* List databases
*
- * @return bool
+ * @return array
*/
public function list_databases()
{
@@ -59,18 +64,25 @@ abstract class CI_DB_utility extends CI_DB_forge {
{
return $this->data_cache['db_names'];
}
+ elseif ($this->_list_databases === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ }
+
+ $this->data_cache['db_names'] = array();
- $query = $this->db->query($this->_list_databases());
- $dbs = array();
- if ($query->num_rows() > 0)
+ $query = $this->db->query($this->_list_databases);
+ if ($query === FALSE)
{
- foreach ($query->result_array() as $row)
- {
- $dbs[] = current($row);
- }
+ return $this->data_cache['db_names'];
+ }
+
+ for ($i = 0, $c = count($query); $i < $c; $i++)
+ {
+ $this->data_cache['db_names'] = current($query[$i]);
}
- return $this->data_cache['db_names'] = $dbs;
+ return $this->data_cache['db_names'];
}
// --------------------------------------------------------------------
@@ -79,48 +91,36 @@ abstract class CI_DB_utility extends CI_DB_forge {
* Determine if a particular database exists
*
* @param string
- * @return boolean
+ * @return bool
*/
public function database_exists($database_name)
{
- // Some databases won't have access to the list_databases() function, so
- // this is intended to allow them to override with their own functions as
- // defined in $driver_utility.php
- if (method_exists($this, '_database_exists'))
- {
- return $this->_database_exists($database_name);
- }
- else
- {
- return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE;
- }
+ return in_array($database_name, $this->list_databases());
}
-
// --------------------------------------------------------------------
/**
* Optimize Table
*
* @param string the table name
- * @return bool
+ * @return mixed
*/
public function optimize_table($table_name)
{
- $sql = $this->_optimize_table($table_name);
-
- if (is_bool($sql))
+ if ($this->_optimize_table === FALSE)
{
- show_error('db_must_use_set');
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- $query = $this->db->query($sql);
- $res = $query->result_array();
+ $query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
+ if ($query !== FALSE)
+ {
+ $query = $query->result_array();
+ return current($res);
+ }
- // Note: Due to a bug in current() that affects some versions
- // of PHP we can not pass function call directly into it
- return current($res);
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -128,26 +128,26 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Database
*
- * @return array
+ * @return mixed
*/
public function optimize_database()
{
+ if ($this->_optimize_table === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ }
+
$result = array();
foreach ($this->db->list_tables() as $table_name)
{
- $sql = $this->_optimize_table($table_name);
-
- if (is_bool($sql))
+ $res = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
+ if (is_bool($res))
{
- return $sql;
+ return $res;
}
- $query = $this->db->query($sql);
-
// Build the result array...
- // Note: Due to a bug in current() that affects some versions
- // of PHP we can not pass function call directly into it
- $res = $query->result_array();
+ $res = $res->result_array();
$res = current($res);
$key = str_replace($this->db->database.'.', '', current($res));
$keys = array_keys($res);
@@ -165,23 +165,23 @@ abstract class CI_DB_utility extends CI_DB_forge {
* Repair Table
*
* @param string the table name
- * @return bool
+ * @return mixed
*/
public function repair_table($table_name)
{
- $sql = $this->_repair_table($table_name);
-
- if (is_bool($sql))
+ if ($this->_repair_table === FALSE)
{
- return $sql;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- $query = $this->db->query($sql);
+ $query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name)));
+ if (is_bool($query))
+ {
+ return $query;
+ }
- // Note: Due to a bug in current() that affects some versions
- // of PHP we can not pass function call directly into it
- $res = $query->result_array();
- return current($res);
+ $query = $query->result_array();
+ return current($query);
}
// --------------------------------------------------------------------
@@ -212,7 +212,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
$out = rtrim($out).$newline;
// Next blast through the result array and build out the rows
- foreach ($query->result_array() as $row)
+ while ($row = $query->unbuffered_row('array'))
{
foreach ($row as $item)
{
@@ -257,18 +257,18 @@ abstract class CI_DB_utility extends CI_DB_forge {
$CI->load->helper('xml');
// Generate the result
- $xml = "<{$root}>".$newline;
- foreach ($query->result_array() as $row)
+ $xml = '<'.$root.'>'.$newline;
+ while ($row = $query->unbuffered_row())
{
- $xml .= $tab."<{$element}>".$newline;
+ $xml .= $tab.'<'.$element.'>'.$newline;
foreach ($row as $key => $val)
{
- $xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline;
+ $xml .= $tab.$tab.'<'.$key.'>'.xml_convert($val).'</'.$key.'>'.$newline;
}
- $xml .= $tab."</{$element}>".$newline;
+ $xml .= $tab.'</'.$element.'>'.$newline;
}
- return $xml .= "</$root>".$newline;
+ return $xml.'</'.$root.'>'.$newline;
}
// --------------------------------------------------------------------
@@ -328,8 +328,8 @@ abstract class CI_DB_utility extends CI_DB_forge {
// 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 (($prefs['format'] === 'gzip' && ! @function_exists('gzencode'))
+ OR ($prefs['format'] === 'zip' && ! @function_exists('gzcompress')))
{
if ($this->db->db_debug)
{
@@ -343,7 +343,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
if ($prefs['format'] === 'zip')
{
// Set the filename if not provided (only needed with Zip files)
- if ($prefs['filename'] == '')
+ if ($prefs['filename'] === '')
{
$prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
.date('Y-m-d_H-i', time()).'.sql';
@@ -369,7 +369,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
$CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
return $CI->zip->get_zip();
}
- elseif ($prefs['format'] == 'txt') // Was a text file requested?
+ elseif ($prefs['format'] === 'txt') // Was a text file requested?
{
return $this->_backup($prefs);
}