diff options
Diffstat (limited to 'system/database')
-rw-r--r-- | system/database/DB_driver.php | 23 | ||||
-rw-r--r-- | system/database/DB_forge.php | 6 | ||||
-rw-r--r-- | system/database/DB_query_builder.php | 2 | ||||
-rw-r--r-- | system/database/drivers/ibase/ibase_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_oci_forge.php | 2 |
6 files changed, 20 insertions, 17 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index de599a675..1dc23d72e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1320,10 +1320,11 @@ abstract class CI_DB_driver { * * This function escapes column and table names * - * @param mixed + * @param mixed $item Identifier to escape + * @param bool $split Whether to split identifiers when a dot is encountered * @return mixed */ - public function escape_identifiers($item) + public function escape_identifiers($item, $split = TRUE) { if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers)) { @@ -1344,22 +1345,22 @@ abstract class CI_DB_driver { return $item; } - static $preg_ec = array(); + static $preg_ec; if (empty($preg_ec)) { if (is_array($this->_escape_char)) { $preg_ec = array( - preg_quote($this->_escape_char[0], '/'), - preg_quote($this->_escape_char[1], '/'), + preg_quote($this->_escape_char[0]), + preg_quote($this->_escape_char[1]), $this->_escape_char[0], $this->_escape_char[1] ); } else { - $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char, '/'); + $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char); $preg_ec[2] = $preg_ec[3] = $this->_escape_char; } } @@ -1368,11 +1369,13 @@ abstract class CI_DB_driver { { if (strpos($item, '.'.$id) !== FALSE) { - return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item); + return preg_replace('#'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\.#i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item); } } - return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item); + $dot = ($split !== FALSE) ? '\.' : ''; + + return preg_replace('#'.$preg_ec[0].'?([^'.$preg_ec[1].$dot.']+)'.$preg_ec[1].'?(\.)?#i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item); } // -------------------------------------------------------------------- @@ -1786,14 +1789,14 @@ abstract class CI_DB_driver { if ($offset = strripos($item, ' AS ')) { $alias = ($protect_identifiers) - ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4)) + ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4), FALSE) : substr($item, $offset); $item = substr($item, 0, $offset); } elseif ($offset = strrpos($item, ' ')) { $alias = ($protect_identifiers) - ? ' '.$this->escape_identifiers(substr($item, $offset + 1)) + ? ' '.$this->escape_identifiers(substr($item, $offset + 1), FALSE) : substr($item, $offset); $item = substr($item, 0, $offset); } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index b52d1fb2b..31fae43cf 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -488,7 +488,7 @@ abstract class CI_DB_forge { * * @param string $table Table name * @param bool $if_exists Whether to add an IF EXISTS condition - * @return string + * @return mixed (Returns a platform-specific DROP table string, or TRUE to indicate there's nothing to do) */ protected function _drop_table($table, $if_exists) { @@ -991,8 +991,8 @@ abstract class CI_DB_forge { /** * Process indexes * - * @param string $table - * @return string + * @param string $table Table name + * @return string[] list of SQL statements */ protected function _process_indexes($table) { diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index ef375227c..102ff4ac0 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1488,7 +1488,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_orderby = NULL; } - $result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby)) + $result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset) ? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results") : $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows'))); diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php index 44bb24e68..31352f128 100644 --- a/system/database/drivers/ibase/ibase_forge.php +++ b/system/database/drivers/ibase/ibase_forge.php @@ -91,7 +91,7 @@ class CI_DB_ibase_forge extends CI_DB_forge { * Create database * * @param string $db_name - * @return string + * @return bool */ public function create_database($db_name) { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 867a94341..724a76df4 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -124,7 +124,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) { $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) - .' '.$this->db->escape_identifiers($field[$i]['new_name']); + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } $field[$i] = "\n\t".$field[$i]['_literal']; diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php index c8983ee56..813207b8e 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php @@ -117,7 +117,7 @@ class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge { if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) { $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) - .' '.$this->db->escape_identifiers($field[$i]['new_name']); + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } } } |