From 4e44b344d79b52c7b79489b7e3d137d5ed66ab21 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 18 Feb 2012 22:47:36 +0700 Subject: Fixed meta table method(s) for PDO --- system/database/drivers/pdo/pdo_driver.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index de2b0abeb..9e8e1f66a 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -591,6 +591,11 @@ class CI_DB_pdo_driver extends CI_DB { // Analog function to show all tables in postgre $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'"; } + elseif ($this->pdodriver == 'sqlite') + { + // Analog function to show all tables in sqlite + $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"; + } else { $sql = "SHOW TABLES FROM `".$this->database."`"; @@ -633,6 +638,22 @@ class CI_DB_pdo_driver extends CI_DB { */ function _field_data($table) { + if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') + { + // Analog function for mysql and postgre + return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1'; + } + elseif ($this->pdodriver == 'oci') + { + // Analog function for oci + return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1'; + } + elseif ($this->pdodriver == 'sqlite') + { + // Analog function for sqlite + return 'PRAGMA table_info('.$this->_from_tables($table).')'; + } + return 'SELECT TOP 1 FROM '.$this->_from_tables($table); } -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 8fdfd58fb..c86d9df60 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 8c332e7f907e6af498f18fa1bf28e0a0c6e11448 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 19 Mar 2012 18:09:13 -0400 Subject: PDO driver access modifiers --- system/database/drivers/pdo/pdo_driver.php | 124 ++++++++++++----------------- 1 file changed, 50 insertions(+), 74 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 658a3d5a0..727f097f8 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -42,28 +42,31 @@ */ class CI_DB_pdo_driver extends CI_DB { - var $dbdriver = 'pdo'; + public $dbdriver = 'pdo'; // the character used to excape - not necessary for PDO - var $_escape_char = ''; + protected $_escape_char = ''; // clause and character used for LIKE escape sequences - var $_like_escape_str; - var $_like_escape_chr; + protected $_like_escape_str; + protected $_like_escape_chr; /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is - * used for the count_all() and count_all_results() functions. + * used for the count_all() and count_all_results() public functions. */ - var $_count_string = "SELECT COUNT(*) AS "; - var $_random_keyword; + protected $_count_string = "SELECT COUNT(*) AS "; + protected $_random_keyword; // need to track the pdo driver and options - var $pdodriver; - var $options = array(); + protected $pdodriver; + protected $options = array(); - function __construct($params) + /** + * Pre-connection setup + */ + public function __construct($params) { parent::__construct($params); @@ -104,11 +107,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Connection String * - * @access private * @param array * @return void */ - function _connect_string($params) + protected function _connect_string($params) { if (strpos($this->hostname, ':')) { @@ -190,10 +192,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Non-persistent database connection * - * @access private called by the base class * @return resource */ - function db_connect() + protected function db_connect() { $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; @@ -205,10 +206,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Persistent database connection * - * @access private called by the base class * @return resource */ - function db_pconnect() + protected function db_pconnect() { $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; $this->options[PDO::ATTR_PERSISTENT] = TRUE; @@ -221,10 +221,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * PDO connection * - * @access private called by the PDO driver class * @return resource */ - function pdo_connect() + protected function pdo_connect() { // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php if ($this->pdodriver == 'mysql' && is_php('5.3.6')) @@ -258,10 +257,9 @@ class CI_DB_pdo_driver extends CI_DB { * Keep / reestablish the db connection if no queries have been * sent for a length of time exceeding the server's idle timeout * - * @access public * @return void */ - function reconnect() + public function reconnect() { if ($this->db->db_debug) { @@ -276,10 +274,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Select the database * - * @access private called by the base class * @return resource */ - function db_select() + protected function db_select() { // Not needed for PDO return TRUE; @@ -304,11 +301,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Execute the query * - * @access private called by the base class * @param string an SQL query * @return object */ - function _execute($sql) + protected function _execute($sql) { $sql = $this->_prep_query($sql); @@ -333,11 +329,10 @@ class CI_DB_pdo_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * @access private called by execute() * @param string an SQL query * @return string */ - function _prep_query($sql) + protected function _prep_query($sql) { if ($this->pdodriver === 'pgsql') { @@ -347,7 +342,7 @@ class CI_DB_pdo_driver extends CI_DB { elseif ($this->pdodriver === 'sqlite') { // Change the backtick(s) for SQLite - $sql = str_replace('`', '', $sql); + $sql = str_replace('`', '"', $sql); } return $sql; @@ -358,10 +353,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ - function trans_begin($test_mode = FALSE) + public function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -387,10 +381,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ - function trans_commit() + public function trans_commit() { if ( ! $this->trans_enabled) { @@ -413,10 +406,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ - function trans_rollback() + public function trans_rollback() { if ( ! $this->trans_enabled) { @@ -439,12 +431,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Escape String * - * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str, $like = FALSE) + public function escape_str($str, $like = FALSE) { if (is_array($str)) { @@ -483,10 +474,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Affected Rows * - * @access public * @return integer */ - function affected_rows() + public function affected_rows() { return $this->affect_rows; } @@ -518,11 +508,10 @@ class CI_DB_pdo_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public * @param string * @return string */ - function count_all($table = '') + public function count_all($table = '') { if ($table == '') { @@ -550,20 +539,19 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private * @param boolean * @return string */ - function _list_tables($prefix_limit = FALSE) + protected function _list_tables($prefix_limit = FALSE) { if ($this->pdodriver == 'pgsql') { - // Analog function to show all tables in postgre + // Analog public function to show all tables in postgre $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'"; } elseif ($this->pdodriver == 'sqlite') { - // Analog function to show all tables in sqlite + // Analog public function to show all tables in sqlite $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"; } else @@ -586,11 +574,10 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access public * @param string the table name * @return string */ - function _list_columns($table = '') + public function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$this->_from_tables($table); } @@ -602,25 +589,24 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public * @param string the table name * @return object */ - function _field_data($table) + public function _field_data($table) { if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') { - // Analog function for mysql and postgre + // Analog public function for mysql and postgre return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1'; } elseif ($this->pdodriver == 'oci') { - // Analog function for oci + // Analog public function for oci return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1'; } elseif ($this->pdodriver == 'sqlite') { - // Analog function for sqlite + // Analog public function for sqlite return 'PRAGMA table_info('.$this->_from_tables($table).')'; } @@ -661,13 +647,12 @@ class CI_DB_pdo_driver extends CI_DB { /** * Escape the SQL Identifiers * - * This function escapes column and table names + * This public function escapes column and table names * - * @access private * @param string * @return string */ - function _escape_identifiers($item) + protected function _escape_identifiers($item) { if ($this->_escape_char == '') { @@ -704,14 +689,13 @@ class CI_DB_pdo_driver extends CI_DB { /** * From Tables * - * This function implicitly groups FROM tables so there is no confusion + * This public function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * @access public * @param type * @return type */ - function _from_tables($tables) + public function _from_tables($tables) { if ( ! is_array($tables)) { @@ -728,13 +712,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ - function _insert($table, $keys, $values) + public function _insert($table, $keys, $values) { return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } @@ -746,13 +729,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ - function _insert_batch($table, $keys, $values) + public function _insert_batch($table, $keys, $values) { return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); } @@ -764,7 +746,6 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific update string from the supplied data * - * @access public * @param string the table name * @param array the update data * @param array the where clause @@ -772,7 +753,7 @@ class CI_DB_pdo_driver extends CI_DB { * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { @@ -796,13 +777,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific batch update string from the supplied data * - * @access public * @param string the table name * @param array the update data * @param array the where clause * @return string */ - function _update_batch($table, $values, $index, $where = NULL) + public function _update_batch($table, $values, $index, $where = NULL) { $ids = array(); $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : ''; @@ -849,13 +829,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific truncate string from the supplied data * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * This public function maps to "DELETE FROM table" * - * @access public * @param string the table name * @return string */ - function _truncate($table) + public function _truncate($table) { return $this->_delete($table); } @@ -867,13 +846,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific delete string from the supplied data * - * @access public * @param string the table name * @param array the where clause * @param string the limit clause * @return string */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) + public function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -902,13 +880,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access public * @param string the sql query string * @param integer the number of rows to limit the query to * @param integer the offset value * @return string */ - function _limit($sql, $limit, $offset) + public function _limit($sql, $limit, $offset) { if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite') { @@ -930,11 +907,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Close DB Connection * - * @access public * @param resource * @return void */ - function _close($conn_id) + public function _close($conn_id) { $this->conn_id = null; } @@ -942,4 +918,4 @@ class CI_DB_pdo_driver extends CI_DB { } /* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */ +/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 667c9feadee8ef5ea8c1859e7c79c2d116469051 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 19 Mar 2012 19:06:34 -0400 Subject: Revert "PDO driver access modifiers" This reverts commit 8c332e7f907e6af498f18fa1bf28e0a0c6e11448. --- system/database/drivers/pdo/pdo_driver.php | 124 +++++++++++++++++------------ 1 file changed, 74 insertions(+), 50 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 727f097f8..658a3d5a0 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -42,31 +42,28 @@ */ class CI_DB_pdo_driver extends CI_DB { - public $dbdriver = 'pdo'; + var $dbdriver = 'pdo'; // the character used to excape - not necessary for PDO - protected $_escape_char = ''; + var $_escape_char = ''; // clause and character used for LIKE escape sequences - protected $_like_escape_str; - protected $_like_escape_chr; + var $_like_escape_str; + var $_like_escape_chr; /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is - * used for the count_all() and count_all_results() public functions. + * used for the count_all() and count_all_results() functions. */ - protected $_count_string = "SELECT COUNT(*) AS "; - protected $_random_keyword; + var $_count_string = "SELECT COUNT(*) AS "; + var $_random_keyword; // need to track the pdo driver and options - protected $pdodriver; - protected $options = array(); + var $pdodriver; + var $options = array(); - /** - * Pre-connection setup - */ - public function __construct($params) + function __construct($params) { parent::__construct($params); @@ -107,10 +104,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Connection String * + * @access private * @param array * @return void */ - protected function _connect_string($params) + function _connect_string($params) { if (strpos($this->hostname, ':')) { @@ -192,9 +190,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Non-persistent database connection * + * @access private called by the base class * @return resource */ - protected function db_connect() + function db_connect() { $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; @@ -206,9 +205,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Persistent database connection * + * @access private called by the base class * @return resource */ - protected function db_pconnect() + function db_pconnect() { $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; $this->options[PDO::ATTR_PERSISTENT] = TRUE; @@ -221,9 +221,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * PDO connection * + * @access private called by the PDO driver class * @return resource */ - protected function pdo_connect() + function pdo_connect() { // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php if ($this->pdodriver == 'mysql' && is_php('5.3.6')) @@ -257,9 +258,10 @@ class CI_DB_pdo_driver extends CI_DB { * Keep / reestablish the db connection if no queries have been * sent for a length of time exceeding the server's idle timeout * + * @access public * @return void */ - public function reconnect() + function reconnect() { if ($this->db->db_debug) { @@ -274,9 +276,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Select the database * + * @access private called by the base class * @return resource */ - protected function db_select() + function db_select() { // Not needed for PDO return TRUE; @@ -301,10 +304,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Execute the query * + * @access private called by the base class * @param string an SQL query * @return object */ - protected function _execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); @@ -329,10 +333,11 @@ class CI_DB_pdo_driver extends CI_DB { * * If needed, each database adapter can prep the query string * + * @access private called by execute() * @param string an SQL query * @return string */ - protected function _prep_query($sql) + function _prep_query($sql) { if ($this->pdodriver === 'pgsql') { @@ -342,7 +347,7 @@ class CI_DB_pdo_driver extends CI_DB { elseif ($this->pdodriver === 'sqlite') { // Change the backtick(s) for SQLite - $sql = str_replace('`', '"', $sql); + $sql = str_replace('`', '', $sql); } return $sql; @@ -353,9 +358,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Begin Transaction * + * @access public * @return bool */ - public function trans_begin($test_mode = FALSE) + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -381,9 +387,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Commit Transaction * + * @access public * @return bool */ - public function trans_commit() + function trans_commit() { if ( ! $this->trans_enabled) { @@ -406,9 +413,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Rollback Transaction * + * @access public * @return bool */ - public function trans_rollback() + function trans_rollback() { if ( ! $this->trans_enabled) { @@ -431,11 +439,12 @@ class CI_DB_pdo_driver extends CI_DB { /** * Escape String * + * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string */ - public function escape_str($str, $like = FALSE) + function escape_str($str, $like = FALSE) { if (is_array($str)) { @@ -474,9 +483,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Affected Rows * + * @access public * @return integer */ - public function affected_rows() + function affected_rows() { return $this->affect_rows; } @@ -508,10 +518,11 @@ class CI_DB_pdo_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * + * @access public * @param string * @return string */ - public function count_all($table = '') + function count_all($table = '') { if ($table == '') { @@ -539,19 +550,20 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * + * @access private * @param boolean * @return string */ - protected function _list_tables($prefix_limit = FALSE) + function _list_tables($prefix_limit = FALSE) { if ($this->pdodriver == 'pgsql') { - // Analog public function to show all tables in postgre + // Analog function to show all tables in postgre $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'"; } elseif ($this->pdodriver == 'sqlite') { - // Analog public function to show all tables in sqlite + // Analog function to show all tables in sqlite $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"; } else @@ -574,10 +586,11 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * + * @access public * @param string the table name * @return string */ - public function _list_columns($table = '') + function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$this->_from_tables($table); } @@ -589,24 +602,25 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * + * @access public * @param string the table name * @return object */ - public function _field_data($table) + function _field_data($table) { if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') { - // Analog public function for mysql and postgre + // Analog function for mysql and postgre return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1'; } elseif ($this->pdodriver == 'oci') { - // Analog public function for oci + // Analog function for oci return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1'; } elseif ($this->pdodriver == 'sqlite') { - // Analog public function for sqlite + // Analog function for sqlite return 'PRAGMA table_info('.$this->_from_tables($table).')'; } @@ -647,12 +661,13 @@ class CI_DB_pdo_driver extends CI_DB { /** * Escape the SQL Identifiers * - * This public function escapes column and table names + * This function escapes column and table names * + * @access private * @param string * @return string */ - protected function _escape_identifiers($item) + function _escape_identifiers($item) { if ($this->_escape_char == '') { @@ -689,13 +704,14 @@ class CI_DB_pdo_driver extends CI_DB { /** * From Tables * - * This public function implicitly groups FROM tables so there is no confusion + * This function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * + * @access public * @param type * @return type */ - public function _from_tables($tables) + function _from_tables($tables) { if ( ! is_array($tables)) { @@ -712,12 +728,13 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * + * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ - public function _insert($table, $keys, $values) + function _insert($table, $keys, $values) { return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } @@ -729,12 +746,13 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * + * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ - public function _insert_batch($table, $keys, $values) + function _insert_batch($table, $keys, $values) { return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); } @@ -746,6 +764,7 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific update string from the supplied data * + * @access public * @param string the table name * @param array the update data * @param array the where clause @@ -753,7 +772,7 @@ class CI_DB_pdo_driver extends CI_DB { * @param array the limit clause * @return string */ - public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { @@ -777,12 +796,13 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific batch update string from the supplied data * + * @access public * @param string the table name * @param array the update data * @param array the where clause * @return string */ - public function _update_batch($table, $values, $index, $where = NULL) + function _update_batch($table, $values, $index, $where = NULL) { $ids = array(); $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : ''; @@ -829,12 +849,13 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific truncate string from the supplied data * If the database does not support the truncate() command - * This public function maps to "DELETE FROM table" + * This function maps to "DELETE FROM table" * + * @access public * @param string the table name * @return string */ - public function _truncate($table) + function _truncate($table) { return $this->_delete($table); } @@ -846,12 +867,13 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific delete string from the supplied data * + * @access public * @param string the table name * @param array the where clause * @param string the limit clause * @return string */ - public function _delete($table, $where = array(), $like = array(), $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -880,12 +902,13 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * + * @access public * @param string the sql query string * @param integer the number of rows to limit the query to * @param integer the offset value * @return string */ - public function _limit($sql, $limit, $offset) + function _limit($sql, $limit, $offset) { if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite') { @@ -907,10 +930,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Close DB Connection * + * @access public * @param resource * @return void */ - public function _close($conn_id) + function _close($conn_id) { $this->conn_id = null; } @@ -918,4 +942,4 @@ class CI_DB_pdo_driver extends CI_DB { } /* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/pdo/pdo_driver.php */ -- cgit v1.2.3-24-g4f1b From 215890b015d219f0d31e8ad678b0b655e6923f3b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 20 Mar 2012 09:38:16 -0400 Subject: Remove extraneous newlines --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 658a3d5a0..9b44e7c64 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -942,4 +942,4 @@ class CI_DB_pdo_driver extends CI_DB { } /* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */ +/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bd44d5a7e12b8eb7f710021f92b6ffd79073cd43 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 22:59:29 +0200 Subject: Visibility declarations and cleanup for CI_DB_pdo_driver --- system/database/drivers/pdo/pdo_driver.php | 186 ++++++++++++----------------- 1 file changed, 77 insertions(+), 109 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 9b44e7c64..0295b9d56 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -1,13 +1,13 @@ -_like_escape_str = " ESCAPE '%s' "; $this->_like_escape_chr = '!'; } - - $this->trans_enabled = FALSE; + + $this->trans_enabled = FALSE; $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } /** * Connection String * - * @access private * @param array * @return void */ - function _connect_string($params) + protected function _connect_string($params) { if (strpos($this->hostname, ':')) { @@ -138,7 +135,7 @@ class CI_DB_pdo_driver extends CI_DB { $this->dsn = $this->pdodriver.':'; // Add hostname to the DSN for databases that need it - if ( ! empty($this->hostname) + if ( ! empty($this->hostname) && strpos($this->hostname, ':') === FALSE && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid'))) { @@ -153,7 +150,7 @@ class CI_DB_pdo_driver extends CI_DB { } // Add the database name to the DSN, if needed - if (stripos($this->dsn, 'dbname') === FALSE + if (stripos($this->dsn, 'dbname') === FALSE && in_array($this->pdodriver, array('4D', 'pgsql', 'mysql', 'firebird', 'sybase', 'mssql', 'dblib', 'cubrid'))) { $this->dsn .= 'dbname='.$this->database.';'; @@ -190,10 +187,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Non-persistent database connection * - * @access private called by the base class - * @return resource + * @return object */ - function db_connect() + public function db_connect() { $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; @@ -205,14 +201,13 @@ class CI_DB_pdo_driver extends CI_DB { /** * Persistent database connection * - * @access private called by the base class - * @return resource + * @return object */ - function db_pconnect() + public function db_pconnect() { - $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; + $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; $this->options[PDO::ATTR_PERSISTENT] = TRUE; - + return $this->pdo_connect(); } @@ -221,23 +216,22 @@ class CI_DB_pdo_driver extends CI_DB { /** * PDO connection * - * @access private called by the PDO driver class - * @return resource + * @return object */ - function pdo_connect() + public function pdo_connect() { // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php - if ($this->pdodriver == 'mysql' && is_php('5.3.6')) + if ($this->pdodriver === 'mysql' && ! is_php('5.3.6')) { $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'"; } // Connecting... - try + try { $db = new PDO($this->dsn, $this->username, $this->password, $this->options); - } - catch (PDOException $e) + } + catch (PDOException $e) { if ($this->db_debug && empty($this->failover)) { @@ -258,10 +252,9 @@ class CI_DB_pdo_driver extends CI_DB { * Keep / reestablish the db connection if no queries have been * sent for a length of time exceeding the server's idle timeout * - * @access public * @return void */ - function reconnect() + public function reconnect() { if ($this->db->db_debug) { @@ -276,10 +269,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Select the database * - * @access private called by the base class * @return resource */ - function db_select() + public function db_select() { // Not needed for PDO return TRUE; @@ -304,16 +296,15 @@ class CI_DB_pdo_driver extends CI_DB { /** * Execute the query * - * @access private called by the base class * @param string an SQL query - * @return object + * @return mixed */ - function _execute($sql) + protected function _execute($sql) { $sql = $this->_prep_query($sql); $result_id = $this->conn_id->query($sql); - + if (is_object($result_id)) { $this->affect_rows = $result_id->rowCount(); @@ -322,7 +313,7 @@ class CI_DB_pdo_driver extends CI_DB { { $this->affect_rows = 0; } - + return $result_id; } @@ -333,11 +324,10 @@ class CI_DB_pdo_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * @access private called by execute() * @param string an SQL query * @return string */ - function _prep_query($sql) + protected function _prep_query($sql) { if ($this->pdodriver === 'pgsql') { @@ -358,10 +348,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ - function trans_begin($test_mode = FALSE) + public function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -387,10 +376,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ - function trans_commit() + public function trans_commit() { if ( ! $this->trans_enabled) { @@ -404,7 +392,7 @@ class CI_DB_pdo_driver extends CI_DB { } $ret = $this->conn->commit(); - + return $ret; } @@ -413,10 +401,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ - function trans_rollback() + public function trans_rollback() { if ( ! $this->trans_enabled) { @@ -439,12 +426,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Escape String * - * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str, $like = FALSE) + public function escape_str($str, $like = FALSE) { if (is_array($str)) { @@ -455,24 +441,22 @@ class CI_DB_pdo_driver extends CI_DB { return $str; } - + //Escape the string $str = $this->conn_id->quote($str); - + //If there are duplicated quotes, trim them away if (strpos($str, "'") === 0) { $str = substr($str, 1, -1); } - + // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', - $this->_like_escape_chr.'_', - $this->_like_escape_chr.$this->_like_escape_chr), - $str); + return str_replace(array($this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), + $str); } return $str; @@ -483,10 +467,9 @@ class CI_DB_pdo_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @return int */ - function affected_rows() + public function affected_rows() { return $this->affect_rows; } @@ -518,7 +501,6 @@ class CI_DB_pdo_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public * @param string * @return string */ @@ -550,11 +532,10 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private - * @param boolean + * @param bool * @return string */ - function _list_tables($prefix_limit = FALSE) + protected function _list_tables($prefix_limit = FALSE) { if ($this->pdodriver == 'pgsql') { @@ -573,7 +554,7 @@ class CI_DB_pdo_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - return FALSE; + return FALSE; } return $sql; @@ -586,11 +567,10 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access public * @param string the table name * @return string */ - function _list_columns($table = '') + protected function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$this->_from_tables($table); } @@ -602,11 +582,10 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public * @param string the table name - * @return object + * @return string */ - function _field_data($table) + protected function _field_data($table) { if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') { @@ -623,7 +602,7 @@ class CI_DB_pdo_driver extends CI_DB { // Analog function for sqlite return 'PRAGMA table_info('.$this->_from_tables($table).')'; } - + return 'SELECT TOP 1 FROM '.$this->_from_tables($table); } @@ -663,11 +642,10 @@ class CI_DB_pdo_driver extends CI_DB { * * This function escapes column and table names * - * @access private * @param string * @return string */ - function _escape_identifiers($item) + public function _escape_identifiers($item) { if ($this->_escape_char == '') { @@ -707,11 +685,10 @@ class CI_DB_pdo_driver extends CI_DB { * This function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * @access public - * @param type - * @return type + * @param array + * @return string */ - function _from_tables($tables) + protected function _from_tables($tables) { if ( ! is_array($tables)) { @@ -728,17 +705,16 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ - function _insert($table, $keys, $values) + protected function _insert($table, $keys, $values) { return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } - + // -------------------------------------------------------------------- /** @@ -746,13 +722,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ - function _insert_batch($table, $keys, $values) + protected function _insert_batch($table, $keys, $values) { return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); } @@ -764,7 +739,6 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific update string from the supplied data * - * @access public * @param string the table name * @param array the update data * @param array the where clause @@ -772,7 +746,7 @@ class CI_DB_pdo_driver extends CI_DB { * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { @@ -788,7 +762,7 @@ class CI_DB_pdo_driver extends CI_DB { return $sql; } - + // -------------------------------------------------------------------- /** @@ -796,13 +770,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific batch update string from the supplied data * - * @access public * @param string the table name * @param array the update data * @param array the where clause * @return string */ - function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index, $where = NULL) { $ids = array(); $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : ''; @@ -841,7 +814,6 @@ class CI_DB_pdo_driver extends CI_DB { return $sql; } - // -------------------------------------------------------------------- /** @@ -851,11 +823,10 @@ class CI_DB_pdo_driver extends CI_DB { * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * - * @access public * @param string the table name * @return string */ - function _truncate($table) + protected function _truncate($table) { return $this->_delete($table); } @@ -867,13 +838,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific delete string from the supplied data * - * @access public * @param string the table name * @param array the where clause * @param string the limit clause * @return string */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -902,13 +872,12 @@ class CI_DB_pdo_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access public * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value + * @param int the number of rows to limit the query to + * @param int the offset value * @return string */ - function _limit($sql, $limit, $offset) + protected function _limit($sql, $limit, $offset) { if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite') { @@ -920,7 +889,7 @@ class CI_DB_pdo_driver extends CI_DB { { $sql .= 'LIMIT '.$limit; $sql .= ($offset > 0) ? ' OFFSET '.$offset : ''; - + return $sql; } } @@ -930,11 +899,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Close DB Connection * - * @access public * @param resource * @return void */ - function _close($conn_id) + protected function _close($conn_id) { $this->conn_id = null; } -- cgit v1.2.3-24-g4f1b From 2cae193647045a83014972d2aae908e7ea0ac8f3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 23 Mar 2012 16:08:41 +0200 Subject: Add dummy method reconnect() method to CI_DB_driver and remove it from drivers that don't support it --- system/database/drivers/pdo/pdo_driver.php | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 0295b9d56..19338e30f 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -246,26 +246,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Reconnect - * - * Keep / reestablish the db connection if no queries have been - * sent for a length of time exceeding the server's idle timeout - * - * @return void - */ - public function reconnect() - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - - return FALSE; - } - - // -------------------------------------------------------------------- - /** * Select the database * -- cgit v1.2.3-24-g4f1b From c6a68e04169802c8aa82e41634ce350eafd1ec1e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 14:30:10 +0300 Subject: Add visibility declarations where they remain missing --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 19338e30f..f336eb0ab 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -484,7 +484,7 @@ class CI_DB_pdo_driver extends CI_DB { * @param string * @return string */ - function count_all($table = '') + public function count_all($table = '') { if ($table == '') { -- cgit v1.2.3-24-g4f1b From bee6644ce280d8e72cc2db23c86d5f5f6973acf3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 28 Mar 2012 15:28:19 +0300 Subject: Add a dummy db_select() method to CI_DB_driver and remove it from drivers that don't have such functionality --- system/database/drivers/pdo/pdo_driver.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index f336eb0ab..a9bed367e 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -246,19 +246,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Select the database - * - * @return resource - */ - public function db_select() - { - // Not needed for PDO - return TRUE; - } - - // -------------------------------------------------------------------- - /** * Database version number * -- cgit v1.2.3-24-g4f1b From 97f3697b6c1c220a32d8e63c5da636e9d725dd8a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Apr 2012 12:44:36 +0300 Subject: Added a default _insert_batch() method instead of requiring each driver to define it and fixed 2 issues related to it --- system/database/drivers/pdo/pdo_driver.php | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index a9bed367e..6ba69b7a5 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -684,23 +684,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); - } - - // -------------------------------------------------------------------- - /** * Update statement * -- cgit v1.2.3-24-g4f1b From 65d537ce35cc01c2f31144d695725255322cb792 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Apr 2012 14:11:41 +0300 Subject: Replaced driver instances of _insert() with one in CI_DB_active_record --- system/database/drivers/pdo/pdo_driver.php | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 6ba69b7a5..17c9f5e9c 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -667,23 +667,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - /** * Update statement * -- cgit v1.2.3-24-g4f1b From 975034d50ed7b3c530631ba3e24a73e33be24eff Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Apr 2012 15:09:55 +0300 Subject: Added a default _update() method to CI_DB_active_record --- system/database/drivers/pdo/pdo_driver.php | 31 ------------------------------ 1 file changed, 31 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 17c9f5e9c..9a08f9d4c 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -667,37 +667,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - $orderby = (count($orderby) >= 1) ? ' ORDER BY '.implode(', ', $orderby) : ''; - - $sql = 'UPDATE '.$this->_from_tables($table).' SET '.implode(', ', $valstr); - $sql .= ($where != '' && count($where) >= 1) ? ' WHERE '.implode(' ', $where) : ''; - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - /** * Update_Batch statement * -- cgit v1.2.3-24-g4f1b From a6fe36eb42e5d8df8336f8c711ff8a6e0ee509e7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Apr 2012 16:00:32 +0300 Subject: Added a default _truncate() method to CI_DB_active_record --- system/database/drivers/pdo/pdo_driver.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 9a08f9d4c..aec39c819 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -722,15 +722,16 @@ class CI_DB_pdo_driver extends CI_DB { * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return $this->_delete($table); + return 'DELETE FROM '.$table; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e9f2095056a579bad9bf2ad80116cc8454f6520e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Apr 2012 19:30:41 +0300 Subject: Fix PDO field and table escaping --- system/database/drivers/pdo/pdo_driver.php | 70 ++++++++---------------------- 1 file changed, 18 insertions(+), 52 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index aec39c819..bd9eddee3 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -46,8 +46,8 @@ class CI_DB_pdo_driver extends CI_DB { protected $_escape_char = ''; // clause and character used for LIKE escape sequences - protected $_like_escape_str; - protected $_like_escape_chr; + protected $_like_escape_str = " ESCAPE '%s' "; + protected $_like_escape_chr = '!'; /** * The syntax to count rows is slightly different across different @@ -81,18 +81,17 @@ class CI_DB_pdo_driver extends CI_DB { // this one depends on the driver being used if ($this->pdodriver == 'mysql') { + $this->_escape_char = '`'; $this->_like_escape_str = ''; $this->_like_escape_chr = ''; } elseif ($this->pdodriver == 'odbc') { $this->_like_escape_str = " {escape '%s'} "; - $this->_like_escape_chr = '!'; } - else + elseif ( ! in_array($this->pdodriver, array('sqlsrv', 'mssql', 'dblib', 'sybase'))) { - $this->_like_escape_str = " ESCAPE '%s' "; - $this->_like_escape_chr = '!'; + $this->_escape_char = '"'; } $this->trans_enabled = FALSE; @@ -268,8 +267,6 @@ class CI_DB_pdo_driver extends CI_DB { */ protected function _execute($sql) { - $sql = $this->_prep_query($sql); - $result_id = $this->conn_id->query($sql); if (is_object($result_id)) @@ -286,32 +283,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @param string an SQL query - * @return string - */ - protected function _prep_query($sql) - { - if ($this->pdodriver === 'pgsql') - { - // Change the backtick(s) for Postgre - $sql = str_replace('`', '"', $sql); - } - elseif ($this->pdodriver === 'sqlite') - { - // Change the backtick(s) for SQLite - $sql = str_replace('`', '', $sql); - } - - return $sql; - } - - // -------------------------------------------------------------------- - /** * Begin Transaction * @@ -516,7 +487,7 @@ class CI_DB_pdo_driver extends CI_DB { } else { - $sql = "SHOW TABLES FROM `".$this->database."`"; + $sql = 'SHOW TABLES FROM '.$this->_escape_identifiers($this->database); } if ($prefix_limit !== FALSE AND $this->dbprefix != '') @@ -539,7 +510,7 @@ class CI_DB_pdo_driver extends CI_DB { */ protected function _list_columns($table = '') { - return 'SHOW COLUMNS FROM '.$this->_from_tables($table); + return 'SHOW COLUMNS FROM '.$this->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -557,20 +528,20 @@ class CI_DB_pdo_driver extends CI_DB { if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') { // Analog function for mysql and postgre - return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1'; + return 'SELECT * FROM '.$this->_escape_identifiers($table).' LIMIT 1'; } elseif ($this->pdodriver == 'oci') { // Analog function for oci - return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1'; + return 'SELECT * FROM '.$this->_escape_identifiers($table).' WHERE ROWNUM <= 1'; } elseif ($this->pdodriver == 'sqlite') { // Analog function for sqlite - return 'PRAGMA table_info('.$this->_from_tables($table).')'; + return 'PRAGMA table_info('.$this->_escape_identifiers($table).')'; } - return 'SELECT TOP 1 FROM '.$this->_from_tables($table); + return 'SELECT TOP 1 FROM '.$this->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -623,25 +594,20 @@ class CI_DB_pdo_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + $item = str_replace('.', $this->_escape_char.'.', $item); // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); } } if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - $str .= $this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; + $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); } // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); } // -------------------------------------------------------------------- @@ -662,7 +628,7 @@ class CI_DB_pdo_driver extends CI_DB { $tables = array($tables); } - return (count($tables) == 1) ? '`'.$tables[0].'`' : '('.implode(', ', $tables).')'; + return (count($tables) === 1) ? $tables[0] : '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- @@ -695,7 +661,7 @@ class CI_DB_pdo_driver extends CI_DB { } } - $sql = 'UPDATE '.$this->_from_tables($table).' SET '; + $sql = 'UPDATE '.$table.' SET '; $cases = ''; foreach ($final as $k => $v) @@ -765,7 +731,7 @@ class CI_DB_pdo_driver extends CI_DB { $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - return 'DELETE FROM '.$this->_from_tables($table).$conditions.$limit; + return 'DELETE FROM '.$table.$conditions.$limit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ea09a8a5552f2aacdeab0c88a605fe44047ebd0a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Apr 2012 20:50:07 +0300 Subject: Renamed _escape_identifiers() to escape_identifiers() and moved it to CI_DB_driver --- system/database/drivers/pdo/pdo_driver.php | 49 ++++-------------------------- 1 file changed, 6 insertions(+), 43 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index bd9eddee3..919bb9c00 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -487,7 +487,7 @@ class CI_DB_pdo_driver extends CI_DB { } else { - $sql = 'SHOW TABLES FROM '.$this->_escape_identifiers($this->database); + $sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database); } if ($prefix_limit !== FALSE AND $this->dbprefix != '') @@ -510,7 +510,7 @@ class CI_DB_pdo_driver extends CI_DB { */ protected function _list_columns($table = '') { - return 'SHOW COLUMNS FROM '.$this->_escape_identifiers($table); + return 'SHOW COLUMNS FROM '.$this->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -528,20 +528,20 @@ class CI_DB_pdo_driver extends CI_DB { if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') { // Analog function for mysql and postgre - return 'SELECT * FROM '.$this->_escape_identifiers($table).' LIMIT 1'; + return 'SELECT * FROM '.$this->escape_identifiers($table).' LIMIT 1'; } elseif ($this->pdodriver == 'oci') { // Analog function for oci - return 'SELECT * FROM '.$this->_escape_identifiers($table).' WHERE ROWNUM <= 1'; + return 'SELECT * FROM '.$this->escape_identifiers($table).' WHERE ROWNUM <= 1'; } elseif ($this->pdodriver == 'sqlite') { // Analog function for sqlite - return 'PRAGMA table_info('.$this->_escape_identifiers($table).')'; + return 'PRAGMA table_info('.$this->escape_identifiers($table).')'; } - return 'SELECT TOP 1 FROM '.$this->_escape_identifiers($table); + return 'SELECT TOP 1 FROM '.$this->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -575,43 +575,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); - } - } - - if (strpos($item, '.') !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); - } - - // -------------------------------------------------------------------- - /** * From Tables * -- cgit v1.2.3-24-g4f1b From 80144bf2badfa992eaef71337e1557209817027c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Apr 2012 22:19:26 +0300 Subject: Fix a CI_DB_pdo_driver::trans_commit() bug --- system/database/drivers/pdo/pdo_driver.php | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 919bb9c00..13ecb24a1 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -290,13 +290,8 @@ class CI_DB_pdo_driver extends CI_DB { */ public function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -318,20 +313,13 @@ class CI_DB_pdo_driver extends CI_DB { */ public function trans_commit() { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } - $ret = $this->conn->commit(); - - return $ret; + return $this->conn_id->commit(); } // -------------------------------------------------------------------- @@ -343,20 +331,13 @@ class CI_DB_pdo_driver extends CI_DB { */ public function trans_rollback() { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } - $ret = $this->conn_id->rollBack(); - - return $ret; + return $this->conn_id->rollBack(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2387ed3057c9c886389df736b3dd3f341d82d1d0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Apr 2012 00:11:14 +0300 Subject: Some minor improvements to the PDO driver --- system/database/drivers/pdo/pdo_driver.php | 59 +++++++++++++----------------- 1 file changed, 26 insertions(+), 33 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 13ecb24a1..5ba0cf8be 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -183,6 +183,8 @@ class CI_DB_pdo_driver extends CI_DB { } } + // -------------------------------------------------------------------- + /** * Non-persistent database connection * @@ -190,9 +192,7 @@ class CI_DB_pdo_driver extends CI_DB { */ public function db_connect() { - $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; - - return $this->pdo_connect(); + return $this->_pdo_connect(); } // -------------------------------------------------------------------- @@ -204,10 +204,7 @@ class CI_DB_pdo_driver extends CI_DB { */ public function db_pconnect() { - $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; - $this->options[PDO::ATTR_PERSISTENT] = TRUE; - - return $this->pdo_connect(); + return $this->_pdo_connect(TRUE); } // -------------------------------------------------------------------- @@ -215,20 +212,29 @@ class CI_DB_pdo_driver extends CI_DB { /** * PDO connection * + * @param bool * @return object */ - public function pdo_connect() + protected function _pdo_connect($persistent = FALSE) { - // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php - if ($this->pdodriver === 'mysql' && ! is_php('5.3.6')) + $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; + $persistent === FALSE OR $this->options[PDO::ATTR_PERSISTENT] = TRUE; + + /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN + * on connect - it was ignored. This is a work-around for the issue. + * + * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php + */ + if ($this->subdriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set)) { - $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'"; + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set + .( ! empty($this->db_collat) ? " COLLATE '".$this->dbcollat."'" : ''); } // Connecting... try { - $db = new PDO($this->dsn, $this->username, $this->password, $this->options); + return new PDO($this->dsn, $this->username, $this->password, $this->options); } catch (PDOException $e) { @@ -239,8 +245,6 @@ class CI_DB_pdo_driver extends CI_DB { return FALSE; } - - return $db; } // -------------------------------------------------------------------- @@ -267,18 +271,7 @@ class CI_DB_pdo_driver extends CI_DB { */ protected function _execute($sql) { - $result_id = $this->conn_id->query($sql); - - if (is_object($result_id)) - { - $this->affect_rows = $result_id->rowCount(); - } - else - { - $this->affect_rows = 0; - } - - return $result_id; + return $this->conn_id->query($sql); } // -------------------------------------------------------------------- @@ -299,7 +292,7 @@ class CI_DB_pdo_driver extends CI_DB { // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. - $this->_trans_failure = (bool) ($test_mode === TRUE); + $this->_trans_failure = ($test_mode === TRUE); return $this->conn_id->beginTransaction(); } @@ -361,10 +354,10 @@ class CI_DB_pdo_driver extends CI_DB { return $str; } - //Escape the string + // Escape the string $str = $this->conn_id->quote($str); - //If there are duplicated quotes, trim them away + // If there are duplicated quotes, trim them away if (strpos($str, "'") === 0) { $str = substr($str, 1, -1); @@ -390,7 +383,7 @@ class CI_DB_pdo_driver extends CI_DB { */ public function affected_rows() { - return $this->affect_rows; + return is_object($this->result_id) ? $this->result_id->rowCount() : 0; } // -------------------------------------------------------------------- @@ -398,6 +391,7 @@ class CI_DB_pdo_driver extends CI_DB { /** * Insert ID * + * @param string * @return int */ public function insert_id($name = NULL) @@ -712,12 +706,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Close DB Connection * - * @param resource * @return void */ - protected function _close($conn_id) + protected function _close() { - $this->conn_id = null; + $this->conn_id = NULL; } } -- cgit v1.2.3-24-g4f1b From c01d31685ad365c6bf3e833c03d7f8a3402c0ec7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 12:55:11 +0300 Subject: Added a default _delete() method to CI_DB_active_record --- system/database/drivers/pdo/pdo_driver.php | 34 ------------------------------ 1 file changed, 34 deletions(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 5ba0cf8be..45f8cc1fb 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -640,40 +640,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return 'DELETE FROM '.$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - /** * Limit string * -- cgit v1.2.3-24-g4f1b From 918be7963f6fa3461d612ea7ca4c9774c12f9da5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 16:29:01 +0300 Subject: Add a parameter to SQLite3 and PDO _close() due to CI_DB_driver being abstract --- system/database/drivers/pdo/pdo_driver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/pdo/pdo_driver.php') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 45f8cc1fb..60151b900 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -672,9 +672,10 @@ class CI_DB_pdo_driver extends CI_DB { /** * Close DB Connection * + * @param object * @return void */ - protected function _close() + protected function _close($conn_id) { $this->conn_id = NULL; } -- cgit v1.2.3-24-g4f1b