From: btongminh Date: Mon, 24 Dec 2012 20:10:22 +0000 (+0100) Subject: Force case-sensitivity on the LIKE operator, to ensure similar behaviour X-Git-Tag: 1.31.0-rc.0~20839^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%22id_auteur=%24connect_id_auteur%22%29%20.%20%22?a=commitdiff_plain;h=3300e5870ca43636e1da34e2aced68ebb148bc6a;p=lhc%2Fweb%2Fwiklou.git Force case-sensitivity on the LIKE operator, to ensure similar behaviour between MySQL and SQLite Change-Id: Idf2d90fe3df07364657abb6070f6eac59add1306 --- diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index d30d984fcc..7e95fd3c21 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -127,6 +127,8 @@ class DatabaseSqlite extends DatabaseBase { # set error codes only, don't raise exceptions if ( $this->mOpened ) { $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); + # Enforce LIKE to be case sensitive, just like MySQL + $this->query( 'PRAGMA case_sensitive_like = 1' ); return true; } } diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index 7958a8aa83..466aa79998 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -372,4 +372,12 @@ class DatabaseSqliteTest extends MediaWikiTestCase { ksort( $indexes ); return $indexes; } + + function testCaseInsensitiveLike() { + // TODO: Test this for all databases + $db = new DatabaseSqliteStandalone( ':memory:' ); + $res = $db->query( 'SELECT "a" LIKE "A" AS a' ); + $row = $res->fetchRow(); + $this->assertFalse( (bool)$row['a'] ); + } }