From 12604d78548c51c1e1aeb91b40066cf554c8e2e2 Mon Sep 17 00:00:00 2001 From: Sergey Tsalkov Date: Sat, 23 Apr 2011 20:31:18 -0400 Subject: [PATCH] bugfix: let people have literal %'s in their queries without confusing the parser by using %% instead --- db.class.php | 3 +++ simpletest/BasicTest.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/db.class.php b/db.class.php index f9c22c1..581df1f 100644 --- a/db.class.php +++ b/db.class.php @@ -270,10 +270,13 @@ class DB while (($pos = strpos($sql, $type, $lastPos)) !== false) { $lastPos = $pos + 1; if (isset($posList[$pos]) && strlen($posList[$pos]) > strlen($type)) continue; + if (substr($sql, $pos - 1, 1) == '%') continue; $posList[$pos] = $type; } } + $sql = str_replace('%%', '%', $sql); + ksort($posList); foreach ($posList as $pos => $type) { diff --git a/simpletest/BasicTest.php b/simpletest/BasicTest.php index 93abb3d..64b98b6 100644 --- a/simpletest/BasicTest.php +++ b/simpletest/BasicTest.php @@ -23,6 +23,11 @@ class BasicTest extends SimpleTest { DB::useDB('libdb_test'); } + function test_0_5_date_format() { + $month = DB::queryFirstField("SELECT DATE_FORMAT(NOW(), '%%b')", 4); + $this->assert($month === date('M')); + } + function test_1_create_table() { DB::query("CREATE TABLE `accounts` (