summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-01-05 19:40:15 +0100
committerAndrey Andreev <narf@bofh.bg>2012-01-05 19:40:15 +0100
commit24abcb98d4281dcf857cb08a86a58af286a2f94a (patch)
tree275449fd18c03c7b4bac72f4490a05e1152a5a7b /system/database/DB_driver.php
parent43fcdbcac05a0cdc5c2a77c79c641849c41caa9e (diff)
Numerous improvements to the Oracle (oci8) driver and DB_driver
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php242
1 files changed, 95 insertions, 147 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 661b42ced..41d170875 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -42,47 +42,44 @@
*/
class CI_DB_driver {
- var $username;
- var $password;
- var $hostname;
- var $database;
- var $dbdriver = 'mysql';
- var $dbprefix = '';
- var $char_set = 'utf8';
- var $dbcollat = 'utf8_general_ci';
- var $autoinit = TRUE; // Whether to automatically initialize the DB
- var $swap_pre = '';
- var $port = '';
- var $pconnect = FALSE;
- var $conn_id = FALSE;
- var $result_id = FALSE;
- var $db_debug = FALSE;
- var $benchmark = 0;
- var $query_count = 0;
- var $bind_marker = '?';
- var $save_queries = TRUE;
- var $queries = array();
- var $query_times = array();
- var $data_cache = array();
- var $trans_enabled = TRUE;
- var $trans_strict = TRUE;
- var $_trans_depth = 0;
- var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
- var $cache_on = FALSE;
- var $cachedir = '';
- var $cache_autodel = FALSE;
- var $CACHE; // The cache class object
-
- // Private variables
- var $_protect_identifiers = TRUE;
- var $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
+ public $username;
+ public $password;
+ public $hostname;
+ public $database;
+ public $dbdriver = 'mysql';
+ public $dbprefix = '';
+ public $char_set = 'utf8';
+ public $dbcollat = 'utf8_general_ci';
+ public $autoinit = TRUE; // Whether to automatically initialize the DB
+ public $swap_pre = '';
+ public $port = '';
+ public $pconnect = FALSE;
+ public $conn_id = FALSE;
+ public $result_id = FALSE;
+ public $db_debug = FALSE;
+ public $benchmark = 0;
+ public $query_count = 0;
+ public $bind_marker = '?';
+ public $save_queries = TRUE;
+ public $queries = array();
+ public $query_times = array();
+ public $data_cache = array();
+ public $trans_enabled = TRUE;
+ public $trans_strict = TRUE;
+ protected $_trans_depth = 0;
+ protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
+ public $cache_on = FALSE;
+ public $cachedir = '';
+ public $cache_autodel = FALSE;
+ public $CACHE; // The cache class object
+
+ protected $_protect_identifiers = TRUE;
+ protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
// These are use with Oracle
- var $stmt_id;
- var $curs_id;
- var $limit_used;
-
-
+ public $stmt_id;
+ public $curs_id;
+ public $limit_used;
/**
* Constructor. Accepts one parameter containing the database
@@ -90,7 +87,7 @@ class CI_DB_driver {
*
* @param array
*/
- function __construct($params)
+ public function __construct($params)
{
if (is_array($params))
{
@@ -108,11 +105,10 @@ class CI_DB_driver {
/**
* Initialize Database Settings
*
- * @access private Called by the constructor
* @param mixed
* @return void
*/
- function initialize()
+ public function initialize()
{
// If an existing connection resource is available
// there is no need to connect and select the database
@@ -200,12 +196,11 @@ class CI_DB_driver {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
* @return resource
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat))
{
@@ -227,10 +222,9 @@ class CI_DB_driver {
/**
* The name of the platform in use (mysql, mssql, etc...)
*
- * @access public
* @return string
*/
- function platform()
+ public function platform()
{
return $this->dbdriver;
}
@@ -241,10 +235,9 @@ class CI_DB_driver {
* Database Version Number. Returns a string containing the
* version of the database being used
*
- * @access public
* @return string
*/
- function version()
+ public function version()
{
if (FALSE === ($sql = $this->_version()))
{
@@ -281,12 +274,11 @@ class CI_DB_driver {
* FALSE upon failure, and if the $db_debug variable is set to TRUE
* will raise an error.
*
- * @access public
* @param string An SQL query string
* @param array An array of binding data
* @return mixed
*/
- function query($sql, $binds = FALSE, $return_object = TRUE)
+ public function query($sql, $binds = FALSE, $return_object = TRUE)
{
if ($sql == '')
{
@@ -410,23 +402,21 @@ class CI_DB_driver {
}
// Load and instantiate the result driver
-
$driver = $this->load_rdriver();
$RES = new $driver();
- $RES->conn_id = $this->conn_id;
- $RES->result_id = $this->result_id;
+ $RES->conn_id = $this->conn_id;
+ $RES->result_id = $this->result_id;
if ($this->dbdriver == 'oci8')
{
$RES->stmt_id = $this->stmt_id;
- $RES->curs_id = NULL;
+ $RES->curs_id = $this->curs_id;
$RES->limit_used = $this->limit_used;
+ // Passing the next one by reference to make sure it's updated, if needed:
+ $RES->commit_mode = &$this->_commit;
$this->stmt_id = FALSE;
}
- // oci8 vars must be set before calling this
- $RES->num_rows = $RES->num_rows();
-
// Is query caching enabled? If so, we'll serialize the
// result object and save it to a cache file.
if ($this->cache_on == TRUE AND $this->_cache_init())
@@ -438,9 +428,9 @@ class CI_DB_driver {
// result object, so we'll have to compile the data
// and save it)
$CR = new CI_DB_result();
- $CR->num_rows = $RES->num_rows();
$CR->result_object = $RES->result_object();
$CR->result_array = $RES->result_array();
+ $CR->num_rows = $RES->num_rows();
// Reset these since cached objects can not utilize resource IDs.
$CR->conn_id = NULL;
@@ -457,10 +447,9 @@ class CI_DB_driver {
/**
* Load the result drivers
*
- * @access public
* @return string the name of the result class
*/
- function load_rdriver()
+ public function load_rdriver()
{
$driver = 'CI_DB_'.$this->dbdriver.'_result';
@@ -481,11 +470,10 @@ class CI_DB_driver {
* we only use it when running transaction commands since they do
* not require all the features of the main query() function.
*
- * @access public
* @param string the sql query
* @return mixed
*/
- function simple_query($sql)
+ public function simple_query($sql)
{
if ( ! $this->conn_id)
{
@@ -504,7 +492,7 @@ class CI_DB_driver {
* @access public
* @return void
*/
- function trans_off()
+ public function trans_off()
{
$this->trans_enabled = FALSE;
}
@@ -521,7 +509,7 @@ class CI_DB_driver {
* @access public
* @return void
*/
- function trans_strict($mode = TRUE)
+ public function trans_strict($mode = TRUE)
{
$this->trans_strict = is_bool($mode) ? $mode : TRUE;
}
@@ -531,10 +519,9 @@ class CI_DB_driver {
/**
* Start Transaction
*
- * @access public
* @return void
*/
- function trans_start($test_mode = FALSE)
+ public function trans_start($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -557,10 +544,9 @@ class CI_DB_driver {
/**
* Complete Transaction
*
- * @access public
* @return bool
*/
- function trans_complete()
+ public function trans_complete()
{
if ( ! $this->trans_enabled)
{
@@ -604,10 +590,9 @@ class CI_DB_driver {
/**
* Lets you retrieve the transaction flag to determine if it has failed
*
- * @access public
* @return bool
*/
- function trans_status()
+ public function trans_status()
{
return $this->_trans_status;
}
@@ -617,12 +602,11 @@ class CI_DB_driver {
/**
* Compile Bindings
*
- * @access public
* @param string the sql statement
* @param array an array of bind data
* @return string
*/
- function compile_binds($sql, $binds)
+ public function compile_binds($sql, $binds)
{
if (strpos($sql, $this->bind_marker) === FALSE)
{
@@ -660,11 +644,10 @@ class CI_DB_driver {
/**
* Determines if a query is a "write" type.
*
- * @access public
* @param string An SQL query string
* @return boolean
*/
- function is_write_type($sql)
+ public function is_write_type($sql)
{
if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
{
@@ -678,11 +661,10 @@ class CI_DB_driver {
/**
* Calculate the aggregate query elapsed time
*
- * @access public
* @param integer The number of decimal places
* @return integer
*/
- function elapsed_time($decimals = 6)
+ public function elapsed_time($decimals = 6)
{
return number_format($this->benchmark, $decimals);
}
@@ -692,10 +674,9 @@ class CI_DB_driver {
/**
* Returns the total number of queries
*
- * @access public
* @return integer
*/
- function total_queries()
+ public function total_queries()
{
return $this->query_count;
}
@@ -705,10 +686,9 @@ class CI_DB_driver {
/**
* Returns the last query that was executed
*
- * @access public
* @return void
*/
- function last_query()
+ public function last_query()
{
return end($this->queries);
}
@@ -721,11 +701,10 @@ class CI_DB_driver {
* Escapes data based on type
* Sets boolean and null types
*
- * @access public
* @param string
* @return mixed
*/
- function escape($str)
+ public function escape($str)
{
if (is_string($str))
{
@@ -751,11 +730,10 @@ class CI_DB_driver {
* Calls the individual driver for platform
* specific escaping for LIKE conditions
*
- * @access public
* @param string
* @return mixed
*/
- function escape_like_str($str)
+ public function escape_like_str($str)
{
return $this->escape_str($str, TRUE);
}
@@ -768,11 +746,10 @@ class CI_DB_driver {
* Retrieves the primary key. It assumes that the row in the first
* position is the primary key
*
- * @access public
* @param string the table name
* @return string
*/
- function primary($table = '')
+ public function primary($table = '')
{
$fields = $this->list_fields($table);
@@ -789,10 +766,9 @@ class CI_DB_driver {
/**
* Returns an array of table names
*
- * @access public
* @return array
*/
- function list_tables($constrain_by_prefix = FALSE)
+ public function list_tables($constrain_by_prefix = FALSE)
{
// Is there a cached result?
if (isset($this->data_cache['table_names']))
@@ -835,12 +811,12 @@ class CI_DB_driver {
/**
* Determine if a particular table exists
- * @access public
+ *
* @return boolean
*/
- function table_exists($table_name)
+ public function table_exists($table_name)
{
- return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE;
+ return in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables());
}
// --------------------------------------------------------------------
@@ -848,11 +824,10 @@ class CI_DB_driver {
/**
* Fetch MySQL Field Names
*
- * @access public
* @param string the table name
* @return array
*/
- function list_fields($table = '')
+ public function list_fields($table = '')
{
// Is there a cached result?
if (isset($this->data_cache['field_names'][$table]))
@@ -901,14 +876,14 @@ class CI_DB_driver {
/**
* Determine if a particular field exists
- * @access public
+ *
* @param string
* @param string
* @return boolean
*/
- function field_exists($field_name, $table_name)
+ public function field_exists($field_name, $table_name)
{
- return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE;
+ return in_array($field_name, $this->list_fields($table_name));
}
// --------------------------------------------------------------------
@@ -916,11 +891,10 @@ class CI_DB_driver {
/**
* Returns an object with field data
*
- * @access public
* @param string the table name
* @return object
*/
- function field_data($table = '')
+ public function field_data($table = '')
{
if ($table == '')
{
@@ -932,7 +906,6 @@ class CI_DB_driver {
}
$query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE)));
-
return $query->field_data();
}
@@ -941,12 +914,11 @@ class CI_DB_driver {
/**
* Generate an insert string
*
- * @access public
* @param string the table upon which the query will be performed
* @param array an associative array data of key/values
* @return string
*/
- function insert_string($table, $data)
+ public function insert_string($table, $data)
{
$fields = array();
$values = array();
@@ -965,13 +937,12 @@ class CI_DB_driver {
/**
* Generate an update string
*
- * @access public
* @param string the table upon which the query will be performed
* @param array an associative array data of key/values
* @param mixed the "where" statement
* @return string
*/
- function update_string($table, $data, $where)
+ public function update_string($table, $data, $where)
{
if ($where == '')
{
@@ -1018,19 +989,12 @@ class CI_DB_driver {
/**
* Tests whether the string has an SQL operator
*
- * @access private
* @param string
* @return bool
*/
- function _has_operator($str)
+ protected function _has_operator($str)
{
- $str = trim($str);
- if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
- {
- return FALSE;
- }
-
- return TRUE;
+ return (bool) preg_match('/(\s|<|>|!|=|is null|is not null)/i', trim($str));
}
// --------------------------------------------------------------------
@@ -1038,12 +1002,11 @@ class CI_DB_driver {
/**
* Enables a native PHP function to be run, using a platform agnostic wrapper.
*
- * @access public
* @param string the function name
* @param mixed any parameters needed by the function
* @return mixed
*/
- function call_function($function)
+ public function call_function($function)
{
$driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
@@ -1080,11 +1043,10 @@ class CI_DB_driver {
/**
* Set Cache Directory Path
*
- * @access public
* @param string the path to the cache directory
* @return void
*/
- function cache_set_path($path = '')
+ public function cache_set_path($path = '')
{
$this->cachedir = $path;
}
@@ -1094,13 +1056,11 @@ class CI_DB_driver {
/**
* Enable Query Caching
*
- * @access public
* @return void
*/
- function cache_on()
+ public function cache_on()
{
- $this->cache_on = TRUE;
- return TRUE;
+ return $this->cache_on = TRUE;
}
// --------------------------------------------------------------------
@@ -1108,13 +1068,11 @@ class CI_DB_driver {
/**
* Disable Query Caching
*
- * @access public
* @return void
*/
- function cache_off()
+ public function cache_off()
{
- $this->cache_on = FALSE;
- return FALSE;
+ return $this->cache_on = FALSE;
}
@@ -1123,10 +1081,9 @@ class CI_DB_driver {
/**
* Delete the cache files associated with a particular URI
*
- * @access public
* @return void
*/
- function cache_delete($segment_one = '', $segment_two = '')
+ public function cache_delete($segment_one = '', $segment_two = '')
{
if ( ! $this->_cache_init())
{
@@ -1140,10 +1097,9 @@ class CI_DB_driver {
/**
* Delete All cache files
*
- * @access public
* @return void
*/
- function cache_delete_all()
+ public function cache_delete_all()
{
if ( ! $this->_cache_init())
{
@@ -1158,22 +1114,18 @@ class CI_DB_driver {
/**
* Initialize the Cache Class
*
- * @access private
* @return void
*/
- function _cache_init()
+ private function _cache_init()
{
if (is_object($this->CACHE) AND class_exists('CI_DB_Cache'))
{
return TRUE;
}
- if ( ! class_exists('CI_DB_Cache'))
+ if ( ! class_exists('CI_DB_Cache') AND ! @include(BASEPATH.'database/DB_cache.php'))
{
- if ( ! @include(BASEPATH.'database/DB_cache.php'))
- {
- return $this->cache_off();
- }
+ return $this->cache_off();
}
$this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
@@ -1185,10 +1137,9 @@ class CI_DB_driver {
/**
* Close DB Connection
*
- * @access public
* @return void
*/
- function close()
+ public function close()
{
if (is_resource($this->conn_id) OR is_object($this->conn_id))
{
@@ -1202,13 +1153,12 @@ class CI_DB_driver {
/**
* Display an error message
*
- * @access public
* @param string the error message
* @param string any "swap" values
* @param boolean whether to localize the message
* @return string sends the application/error_db.php template
*/
- function display_error($error = '', $swap = '', $native = FALSE)
+ public function display_error($error = '', $swap = '', $native = FALSE)
{
$LANG =& load_class('Lang', 'core');
$LANG->load('db');
@@ -1254,11 +1204,10 @@ class CI_DB_driver {
*
* This function adds backticks if appropriate based on db type
*
- * @access private
* @param mixed the item to escape
* @return mixed the item with backticks
*/
- function protect_identifiers($item, $prefix_single = FALSE)
+ public function protect_identifiers($item, $prefix_single = FALSE)
{
return $this->_protect_identifiers($item, $prefix_single);
}
@@ -1285,14 +1234,14 @@ class CI_DB_driver {
* insert the table prefix (if it exists) in the proper position, and escape only
* the correct identifiers.
*
- * @access private
+ * @access public (DB Forge needs it to be public!)
* @param string
* @param bool
* @param mixed
* @param bool
* @return string
*/
- function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
+ public function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
{
if ( ! is_bool($protect_identifiers))
{
@@ -1440,6 +1389,5 @@ class CI_DB_driver {
}
-
/* End of file DB_driver.php */
/* Location: ./system/database/DB_driver.php */