From a9194650e6ae387be29aacfdf4b1b27a5c60ca34 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 27 Sep 2017 18:57:46 +0300 Subject: Fix #5276 --- system/database/drivers/mysqli/mysqli_result.php | 14 +++----------- system/database/drivers/mysqli/mysqli_utility.php | 6 +----- 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 0b3d9c2b4..bd465c405 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -130,10 +130,10 @@ class CI_DB_mysqli_result extends CI_DB_result { * mysqli_result::fetch_fields() * * @used-by CI_DB_mysqli_result::field_data() - * @param int $flags + * @param int $type * @return string */ - private static function _get_field_type($flags) + private static function _get_field_type($type) { static $map; isset($map) OR $map = array( @@ -164,15 +164,7 @@ class CI_DB_mysqli_result extends CI_DB_result { MYSQLI_TYPE_GEOMETRY => 'geometry' ); - foreach ($map as $flag => $name) - { - if ($flags & $flag) - { - return $name; - } - } - - return $flags; + return isset($map[$type]) ? $map[$type] : $type; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 1699b611f..82cf5cebf 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -155,11 +155,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { while ($field = $query->result_id->fetch_field()) { // Most versions of MySQL store timestamp as a string - $is_int[$i] = ($field->type & MYSQLI_TYPE_TINY) - OR ($field->type & MYSQLI_TYPE_SHORT) - OR ($field->type & MYSQLI_TYPE_INT24) - OR ($field->type & MYSQLI_TYPE_LONG) - OR ($field->type & MYSQLI_TYPE_LONGLONG); + $is_int[$i] = in_array($field->type, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_INT24, MYSQLI_TYPE_LONG), TRUE); // Create a string of field names $field_str .= $this->db->escape_identifiers($field->name).', '; -- cgit v1.2.3-24-g4f1b From cf3924ec3f19fb6a3f4782cfe55e0c6314bcf94d Mon Sep 17 00:00:00 2001 From: pgee70 Date: Tue, 3 Oct 2017 10:09:04 +1100 Subject: Update DB_query_builder.php recent changes broke query ordering giving a warning in line 1238 = '$this->qb_cache_orderby = array_merge($this->qb_cache_orderby, $qb_orderby);' this was because on subsequent re-queries, the qb_cache_orderby was set to NULL not Array() as it is should be (and is instantiated originally . --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 81603bf31..72bd4e721 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1405,7 +1405,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // for selecting COUNT(*) ... $qb_orderby = $this->qb_orderby; $qb_cache_orderby = $this->qb_cache_orderby; - $this->qb_orderby = $this->qb_cache_orderby = NULL; + $this->qb_orderby = $this->qb_cache_orderby = array(); $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") -- cgit v1.2.3-24-g4f1b From fa2a0c58eb0f6421e3819df8a8873b5a5e4ebb58 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 13 Oct 2017 17:04:35 +0300 Subject: Fix #5297 --- system/database/DB_driver.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 0b13a2f82..c18701db3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1926,15 +1926,19 @@ abstract class CI_DB_driver { $i++; } + // dbprefix may've already been applied, with or without the identifier escaped + $ec = '(?'.preg_quote(is_array($this->_escape_char) ? $this->_escape_char[0] : $this->_escape_char).')?'; + isset($ec[0]) && $ec .= '?'; // Just in case someone has disabled escaping by forcing an empty escape character + // Verify table prefix and replace if necessary - if ($this->swap_pre !== '' && strpos($parts[$i], $this->swap_pre) === 0) + if ($this->swap_pre !== '' && preg_match('#^'.$ec.preg_quote($this->swap_pre).'#', $parts[$i])) { - $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]); + $parts[$i] = preg_replace('#^'.$ec.preg_quote($this->swap_pre).'(\S+?)#', '\\1'.$this->dbprefix.'\\2', $parts[$i]); } // We only add the table prefix if it does not already exist - elseif (strpos($parts[$i], $this->dbprefix) !== 0) + else { - $parts[$i] = $this->dbprefix.$parts[$i]; + preg_match('#^'.$ec.preg_quote($this->dbprefix).'#', $parts[$i]) OR $parts[$i] = $this->dbprefix.$parts[$i]; } // Put the parts back together -- cgit v1.2.3-24-g4f1b