diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-06-12 13:16:53 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-06-12 13:16:53 +0200 |
commit | 4e9538fe19b09c0dc588542cfb7f793348b83bf7 (patch) | |
tree | 8466951d2e0b48b7d8de366fd4a72ca45563f428 | |
parent | cce918033a99186cd76019d022571a8d9321d899 (diff) |
Fix issue #145
-rw-r--r-- | system/database/DB_driver.php | 26 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 |
2 files changed, 10 insertions, 17 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 079ee8d05..88a3b388f 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,35 +596,27 @@ abstract class CI_DB_driver { */ public function compile_binds($sql, $binds) { - if (strpos($sql, $this->bind_marker) === FALSE) + if (preg_match_all('/(>|<|=|!)\s*('.preg_quote($this->bind_marker).')/i', $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) { return $sql; } - - if ( ! is_array($binds)) + elseif ( ! is_array($binds)) { $binds = array($binds); } - - // Get the sql segments around the bind markers - $segments = explode($this->bind_marker, $sql); - - // The count of bind should be 1 less then the count of segments - // If there are more bind arguments trim it down - if (count($binds) >= count($segments)) + else { - $binds = array_slice($binds, 0, count($segments)-1); + // Make sure we're using numeric keys + $binds = array_values($binds); } - // Construct the binded query - $result = $segments[0]; - $i = 0; - foreach ($binds as $bind) + + for ($i = count($matches) - 1; $i >= 0; $i--) { - $result .= $this->escape($bind).$segments[++$i]; + $sql = substr_replace($sql, $this->escape($binds[$i]), $matches[$i][2][1], 1); } - return $result; + return $sql; } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 4962caa7d..ab3e01394 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -263,6 +263,7 @@ Bug fixes for 3.0 - Fixed a bug (#1321) - Core Exceptions class couldn't find the errors/ folder in some cases. - Fixed a bug in the File-based :doc:`Cache Library <libraries/caching>` driver's get_metadata() method where a non-existent array key was accessed for the TTL value. - Fixed a bug (#1202) - :doc:`Encryption Library <libraries/encryption>` encode_from_legacy() didn't set back the encrypt mode on failure. +- Fixed a bug (#145) - compile_binds() failed when the bind marker was present in a literal string within the query. Version 2.1.1 ============= |