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 :)
This commit is contained in:
Sergey Tsalkov
2011-04-22 23:29:09 -04:00
parent 68774532e1
commit 964a36e4c2
2 changed files with 7 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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;