From 75546118c628fc17ba2f1ef97442760a701aa8e8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 11:01:29 +0300 Subject: Move _insert() and _update() defaults from Query Builder to DB_driver so that they're available for use by insert_string() and update_string() at all times --- system/database/DB.php | 11 ++++--- system/database/DB_driver.php | 63 ++++++++++++++++++++++++++++++++++-- system/database/DB_query_builder.php | 52 ----------------------------- 3 files changed, 67 insertions(+), 59 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 3044ce517..032cf1b76 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -29,8 +29,8 @@ * Initialize the database * * @category Database - * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/database/ + * @author EllisLab Dev Team + * @link http://codeigniter.com/user_guide/database/ * @param string * @param bool Determines if query builder should be used or not */ @@ -159,7 +159,10 @@ function &DB($params = '', $query_builder_override = NULL) // Load the DB driver $driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'; - if ( ! file_exists($driver_file)) show_error('Invalid DB driver'); + if ( ! file_exists($driver_file)) + { + show_error('Invalid DB driver'); + } require_once($driver_file); @@ -181,4 +184,4 @@ function &DB($params = '', $query_builder_override = NULL) } /* End of file DB.php */ -/* Location: ./system/database/DB.php */ +/* Location: ./system/database/DB.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 334bdbd04..ebf828c4e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -45,7 +45,7 @@ abstract class CI_DB_driver { public $password; public $hostname; public $database; - public $dbdriver = 'mysql'; + public $dbdriver = 'mysqli'; public $dbprefix = ''; public $char_set = 'utf8'; public $dbcollat = 'utf8_general_ci'; @@ -77,6 +77,12 @@ abstract class CI_DB_driver { protected $_protect_identifiers = TRUE; protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped + /** + * Constructor + * + * @param array + * @return void + */ public function __construct($params) { if (is_array($params)) @@ -855,7 +861,7 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- /** - * Fetch MySQL Field Names + * Fetch Field Names * * @param string the table name * @return array @@ -1029,6 +1035,23 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- + /** + * 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 '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + /** * Generate an update string * @@ -1081,6 +1104,41 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- + /** + * 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 + * @param array the like clause + * @return string + */ + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + { + foreach ($values as $key => $val) + { + $valstr[] = $key.' = '.$val; + } + + $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); + + if ( ! empty($like)) + { + $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); + } + + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .$where + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .($limit ? ' LIMIT '.$limit : ''); + } + + // -------------------------------------------------------------------- + /** * Tests whether the string has an SQL operator * @@ -1171,7 +1229,6 @@ abstract class CI_DB_driver { return $this->cache_on = FALSE; } - // -------------------------------------------------------------------- /** diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 3982885e8..79e67e0c0 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1434,23 +1434,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * 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 '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - /** * Validate Insert * @@ -1630,41 +1613,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * 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 - * @param array the like clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) - { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .$where - .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') - .($limit ? ' LIMIT '.$limit : ''); - } - - // -------------------------------------------------------------------- - /** * Validate Update * -- cgit v1.2.3-24-g4f1b