function DatabaseBasicSyntaxTestCase::testLikeEscape

Test escaping of LIKE wildcards.

File

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

Class

DatabaseBasicSyntaxTestCase
Test how the current database driver interprets the SQL syntax.

Code

function testLikeEscape() {
    db_insert('test')->fields(array(
        'name' => 'Ring_',
    ))
        ->execute();
    // Match both "Ringo" and "Ring_".
    $num_matches = db_select('test', 't')->condition('name', 'Ring_', 'LIKE')
        ->countQuery()
        ->execute()
        ->fetchField();
    $this->assertIdentical($num_matches, '2', 'Found 2 records.');
    // Match only "Ring_" using a LIKE expression with no wildcards.
    $num_matches = db_select('test', 't')->condition('name', db_like('Ring_'), 'LIKE')
        ->countQuery()
        ->execute()
        ->fetchField();
    $this->assertIdentical($num_matches, '1', 'Found 1 record.');
}

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