Commit d141c5a7 authored by webchick's avatar webchick
Browse files

Issue #2475247 by amateescu, dawehner: SQLite: Fix views\Tests\Handler\FilterStringTest

parent 3289027c
...@@ -39,7 +39,10 @@ protected function getStatement($query, &$args = array()) { ...@@ -39,7 +39,10 @@ protected function getStatement($query, &$args = array()) {
$count = 0; $count = 0;
$new_args = array(); $new_args = array();
foreach ($args as $value) { foreach ($args as $value) {
if (is_float($value) || is_int($value)) { // Integers expressed as strings (e.g. '5') have to treated as numeric
// values. Sadly, PHP has an upper limit on integers, PHP_INT_MAX, so
// we can not support numbers higher than that.
if (is_float($value) || is_int($value) || (is_numeric($value) && $value <= PHP_INT_MAX)) {
if (is_float($value)) { if (is_float($value)) {
// Force the conversion to float so as not to loose precision // Force the conversion to float so as not to loose precision
// in the automatic cast. // in the automatic cast.
...@@ -58,7 +61,10 @@ protected function getStatement($query, &$args = array()) { ...@@ -58,7 +61,10 @@ protected function getStatement($query, &$args = array()) {
else { else {
// Else, this is using named placeholders. // Else, this is using named placeholders.
foreach ($args as $placeholder => $value) { foreach ($args as $placeholder => $value) {
if (is_float($value) || is_int($value)) { // Integers expressed as strings (e.g. '5') have to treated as numeric
// values. Sadly, PHP has an upper limit on integers, PHP_INT_MAX, so
// we can not support numbers higher than that.
if (is_float($value) || is_int($value) || (is_numeric($value) && $value <= PHP_INT_MAX)) {
if (is_float($value)) { if (is_float($value)) {
// Force the conversion to float so as not to loose precision // Force the conversion to float so as not to loose precision
// in the automatic cast. // in the automatic cast.
......
...@@ -69,7 +69,7 @@ public function testArrayArgumentsSQLInjection() { ...@@ -69,7 +69,7 @@ public function testArrayArgumentsSQLInjection() {
/** /**
* Tests numeric query parameter expansion in expressions. * Tests numeric query parameter expansion in expressions.
* *
* @see \Drupal\Core\Database\Driver\sqlite\Connection::expandArguments() * @see \Drupal\Core\Database\Driver\sqlite\Statement::getStatement()
* @see http://bugs.php.net/bug.php?id=45259 * @see http://bugs.php.net/bug.php?id=45259
*/ */
public function testNumericExpressionSubstitution() { public function testNumericExpressionSubstitution() {
...@@ -80,6 +80,12 @@ public function testNumericExpressionSubstitution() { ...@@ -80,6 +80,12 @@ public function testNumericExpressionSubstitution() {
':count' => 3, ':count' => 3,
))->fetchField(); ))->fetchField();
$this->assertEqual((bool) $count, TRUE); $this->assertEqual((bool) $count, TRUE);
// Test that numeric arguments expressed as strings also work properly.
$count = db_query('SELECT COUNT(*) >= :count FROM {test}', array(
':count' => (string) 3,
))->fetchField();
$this->assertEqual((bool) $count, TRUE);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment