diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 8c625ff62..f2aa64ebc 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1904,6 +1904,7 @@ class DboSource extends DataSource { $key = substr($key, 0, $split); } } + $type = (is_object($model) ? $model->getColumnType($key) : null); $null = ($value === null || (is_array($value) && empty($value))); @@ -1915,9 +1916,10 @@ class DboSource extends DataSource { } $value = $this->value($value, $type); - $key = (strpos($key, '(') !== false || strpos($key, ')') !== false) ? - $this->__quoteFields($key) : - $this->name($key); + if ($key !== '?') { + $isKey = (strpos($key, '(') !== false || strpos($key, ')') !== false); + $key = $isKey ? $this->__quoteFields($key) : $this->name($key); + } if ($bound) { return String::insert($key . ' ' . trim($operator), $value); diff --git a/cake/libs/router.php b/cake/libs/router.php index 3b496da25..4071c6f12 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -215,7 +215,7 @@ class Router extends Object { return $_this->routes; } /** - *Specifies what named parameters CakePHP should be parsing. The most common setups are: + * Specifies what named parameters CakePHP should be parsing. The most common setups are: * * Do not parse any named parameters: * {{{ Router::connectNamed(false); }}} diff --git a/cake/libs/string.php b/cake/libs/string.php index 8639e5f4f..8c73551a6 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -211,10 +211,10 @@ class String extends Object { * @static */ function insert($str, $data, $options = array()) { - $options = array_merge( - array('before' => ':', 'after' => null, 'escape' => '\\', 'format' => null, 'clean' => false), - $options + $defaults = array( + 'before' => ':', 'after' => null, 'escape' => '\\', 'format' => null, 'clean' => false ); + $options += $defaults; $format = $options['format']; if (!isset($format)) { @@ -231,7 +231,7 @@ class String extends Object { if (array_keys($data) === array_keys(array_values($data))) { $offset = 0; - while ($pos = strpos($str, '?', $offset)) { + while (($pos = strpos($str, '?', $offset)) !== false) { $val = array_shift($data); $offset = $pos + strlen($val); $str = substr_replace($str, $val, $pos, 1); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 61019add0..54375cf7e 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2404,12 +2404,10 @@ class DboSourceTest extends CakeTestCase { $expected = " WHERE `client_id` > 20"; $this->assertEqual($result, $expected); - $result = $this->testDb->conditions(array( - 'OR' => array( - array('User.user' => 'mariano'), - array('User.user' => 'nate') - ) - )); + $result = $this->testDb->conditions(array('OR' => array( + array('User.user' => 'mariano'), + array('User.user' => 'nate') + ))); $expected = " WHERE ((`User`.`user` = 'mariano') OR (`User`.`user` = 'nate'))"; $this->assertEqual($result, $expected); @@ -2545,6 +2543,12 @@ class DboSourceTest extends CakeTestCase { )); $expected = ' WHERE ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN 65 AND 90'; $this->assertEqual($result, $expected); + + $result = $this->testDb->conditions(array('or' => array( + '? BETWEEN Model.field1 AND Model.field2' => '2009-03-04' + ))); + $expected = " WHERE '2009-03-04' BETWEEN Model.field1 AND Model.field2"; + $this->assertEqual($result, $expected); } /** * testArrayConditionsParsingComplexKeys method diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index f544ca41c..eacdd181e 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -40,7 +40,8 @@ class StringTest extends CakeTestCase { */ function testUuidGeneration() { $result = String::uuid(); - $match = preg_match("/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/", $result); + $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/"; + $match = preg_match($pattern, $result); $this->assertTrue($match); } /** @@ -52,9 +53,11 @@ class StringTest extends CakeTestCase { function testMultipleUuidGeneration() { $check = array(); $count = mt_rand(10, 1000); + $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/"; + for($i = 0; $i < $count; $i++) { $result = String::uuid(); - $match = preg_match("/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/", $result); + $match = preg_match($pattern, $result); $this->assertTrue($match); $this->assertFalse(in_array($result, $check)); $check[] = $result; @@ -179,9 +182,17 @@ class StringTest extends CakeTestCase { $expected = "We are of course passing."; $this->assertEqual($result, $expected); - $result = String::insert(':I.am: :not.yet: passing.', array('I.am' => 'We are'), array('before' => ':', 'after' => ':', 'clean' => true)); + $result = String::insert( + ':I.am: :not.yet: passing.', + array('I.am' => 'We are'), + array('before' => ':', 'after' => ':', 'clean' => true) + ); $expected = "We are passing."; $this->assertEqual($result, $expected); + + $result = String::insert('?-pended result', array('Pre')); + $expected = "Pre-pended result"; + $this->assertEqual($result, $expected); } /** * test Clean Insert