Commit 19a7f811 authored by alexpott's avatar alexpott

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

parent 30063228
......@@ -39,10 +39,7 @@ protected function getStatement($query, &$args = array()) {
$count = 0;
$new_args = array();
foreach ($args as $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) || is_int($value)) {
if (is_float($value)) {
// Force the conversion to float so as not to loose precision
// in the automatic cast.
......@@ -61,10 +58,7 @@ protected function getStatement($query, &$args = array()) {
else {
// Else, this is using named placeholders.
foreach ($args as $placeholder => $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) || is_int($value)) {
if (is_float($value)) {
// Force the conversion to float so as not to loose precision
// in the automatic cast.
......
......@@ -80,12 +80,6 @@ public function testNumericExpressionSubstitution() {
':count' => 3,
))->fetchField();
$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);
}
}
......@@ -320,12 +320,16 @@ protected function opNotLike($field) {
protected function opShorterThan($field) {
$placeholder = $this->placeholder();
$this->query->addWhereExpression($this->options['group'], "LENGTH($field) < $placeholder", array($placeholder => $this->value));
// Type cast the argument to an integer because the SQLite database driver
// has to do some specific alterations to the query base on that data type.
$this->query->addWhereExpression($this->options['group'], "LENGTH($field) < $placeholder", array($placeholder => (int) $this->value));
}
protected function opLongerThan($field) {
$placeholder = $this->placeholder();
$this->query->addWhereExpression($this->options['group'], "LENGTH($field) > $placeholder", array($placeholder => $this->value));
// Type cast the argument to an integer because the SQLite database driver
// has to do some specific alterations to the query base on that data type.
$this->query->addWhereExpression($this->options['group'], "LENGTH($field) > $placeholder", array($placeholder => (int) $this->value));
}
/**
......
......@@ -745,7 +745,18 @@ function _views_query_tag_alter_condition(AlterableInterface $query, &$condition
views_query_views_alter($condition['value']);
}
elseif (isset($condition['value'])) {
$condition['value'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['value']);
// We can not use a simple str_replace() here because it always returns
// a string and we have to keep the type of the condition value intact.
if (is_array($condition['value'])) {
foreach ($condition['value'] as &$value) {
if (is_string($value)) {
$value = str_replace(array_keys($substitutions), array_values($substitutions), $value);
}
}
}
elseif (is_string($condition['value'])) {
$condition['value'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['value']);
}
}
}
}
......
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