function DatabaseUpdateComplexTestCase::testUpdateOnlyExpression

Test update with only expression values.

File

modules/simpletest/tests/database_test.test, line 1075

Class

DatabaseUpdateComplexTestCase
Tests for more complex update statements.

Code

function testUpdateOnlyExpression() {
    $before_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
        ':name' => 'Ringo',
    ))->fetchField();
    $num_updated = db_update('test')->condition('name', 'Ringo')
        ->expression('age', 'age + :age', array(
        ':age' => 4,
    ))
        ->execute();
    $this->assertIdentical($num_updated, 1, 'Updated 1 record.');
    $after_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
        ':name' => 'Ringo',
    ))->fetchField();
    $this->assertEqual($before_age + 4, $after_age, 'Age updated correctly');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.