Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
8eb5874e
Commit
8eb5874e
authored
Dec 22, 2010
by
Angie Byron
Browse files
#1004060
by dmitrig01, chx: Fixed SQLite update queries with expression failing
parent
dc51c88a
Changes
2
Hide whitespace changes
Inline
Side-by-side
includes/database/sqlite/query.inc
View file @
8eb5874e
...
...
@@ -97,7 +97,7 @@ public function execute() {
foreach
(
$fields
as
$field
=>
$data
)
{
if
(
is_array
(
$data
))
{
// The field is an expression.
$condition
->
condition
(
$field
,
$data
[
'expression'
]
,
'<>'
);
$condition
->
where
(
$field
.
' <> '
.
$data
[
'expression'
]);
$condition
->
isNull
(
$field
);
}
elseif
(
!
isset
(
$data
))
{
...
...
modules/simpletest/tests/database_test.test
View file @
8eb5874e
...
...
@@ -776,6 +776,25 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
$this
->
assertIdentical
(
$num_matches
,
'1'
,
t
(
'Updated fields successfully.'
));
}
/**
* Test updating with expressions.
*/
function
testExpressionUpdate
()
{
// Set age = 1 for a single row for this test to work.
db_update
(
'test'
)
->
condition
(
'id'
,
1
)
->
fields
(
array
(
'age'
=>
1
))
->
execute
();
// Ensure that expressions are handled properly. This should set every
// record's age to a square of itself, which will change only three of the
// four records in the table since 1*1 = 1. That means only three records
// are modified, so we should get back 3, not 4, from execute().
$num_rows
=
db_update
(
'test'
)
->
expression
(
'age'
,
'age * age'
)
->
execute
();
$this
->
assertIdentical
(
$num_rows
,
3
,
t
(
'Number of affected rows are returned.'
));
}
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment