From 964a36e4c23c01d0581c43962a37eec47408a5a0 Mon Sep 17 00:00:00 2001 From: Sergey Tsalkov Date: Fri, 22 Apr 2011 23:29:09 -0400 Subject: [PATCH] sqleval() can now be used with %s, %i, and all that good stuff there is probably no good reason to do this, as things like md5() can be done from PHP, but people keep asking for it, so here it is :) --- db.class.php | 4 +++- simpletest/BasicTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/db.class.php b/db.class.php index b0023b3..d5a458e 100644 --- a/db.class.php +++ b/db.class.php @@ -181,7 +181,9 @@ class DB call_user_func_array('DB::queryNull', $args); } - public static function sqleval($text) { + public static function sqleval() { + $args = func_get_args(); + $text = call_user_func_array('DB::parseQueryParams', $args); return new MeekroDBEval($text); } diff --git a/simpletest/BasicTest.php b/simpletest/BasicTest.php index 3e83fdc..e72d8e7 100644 --- a/simpletest/BasicTest.php +++ b/simpletest/BasicTest.php @@ -135,16 +135,17 @@ class BasicTest extends SimpleTest { function test_4_1_query() { DB::insert('accounts', array( 'username' => 'newguy', - 'password' => DB::sqleval("REPEAT('blah', 3)"), - 'age' => 172, + 'password' => DB::sqleval("REPEAT('blah', %i)", '3'), + 'age' => DB::sqleval('171+1'), 'height' => 111.15 )); $row = DB::queryOneRow("SELECT * FROM accounts WHERE password=%s", 'blahblahblah'); $this->assert($row['username'] === 'newguy'); + $this->assert($row['age'] === '172'); DB::update('accounts', array( - 'password' => DB::sqleval("REPEAT('blah', 4)"), + 'password' => DB::sqleval("REPEAT('blah', %i)", 4), ), 'username=%s', 'newguy'); $row = null;