Permalink
Browse files

remove help method, update tests

now test use DibiTranslator
  • Loading branch information...
chemix committed Dec 14, 2014
1 parent 45ccff3 commit 13bbed3d48387aee640a54605995ea93934464da
Showing with 5 additions and 26 deletions.
  1. +0 −22 dibi/libs/DibiConnection.php
  2. +5 −4 tests/dibi/mysql/query.phpt
@@ -282,28 +282,6 @@ public static function alias(& $config, $key, $alias)
}
}
/**
* Generates and return SQL query.
* @param array|mixed one or more arguments
* @return string|FALSE
*/
final public function testQuery($args)
{
$args = func_get_args();
try {
return $this->translateArgs($args);
} catch (DibiException $e) {
if ($e->getSql()) {
dibi::dump($e->getSql());
} else {
echo get_class($e) . ': ' . $e->getMessage() . (PHP_SAPI === 'cli' ? "\n" : '<br>');
}
return FALSE;
}
}
/**
* Generates (translates) and returns SQL query as DibiDataSource.
@@ -14,19 +14,20 @@ $options = $config['mysql'];
$options['lazy'] = TRUE;
$connection = new DibiConnection($options);
$translator = new DibiTranslator($connection);
// %s
$SQL = $connection->testQuery("SELECT [username] FROM [users] WHERE [user] = %s", 'admin');
$SQL = $translator->translate(["SELECT [username] FROM [users] WHERE [user] = %s", 'admin']);
Assert::same("SELECT `username` FROM `users` WHERE `user` = 'admin'", $SQL);
// %i
$SQL = $connection->testQuery("SELECT [username] FROM [users] WHERE [id] = %i", 10);
$SQL = $translator->translate(["SELECT [username] FROM [users] WHERE [id] = %i", 10]);
Assert::same("SELECT `username` FROM `users` WHERE `id` = 10", $SQL);
// %n
$SQL = $connection->testQuery("SELECT %n FROM %n WHERE %n = %i", 'username', 'users', 'id', 10);
$SQL = $translator->translate(["SELECT %n FROM %n WHERE %n = %i", 'username', 'users', 'id', 10]);
Assert::same("SELECT `username` FROM `users` WHERE `id` = 10", $SQL);
// %b
$SQL = $connection->testQuery("SELECT [username] FROM [users] WHERE [active] = %b", TRUE);
$SQL = $translator->translate(["SELECT [username] FROM [users] WHERE [active] = %b", TRUE]);
Assert::same("SELECT `username` FROM `users` WHERE `active` = 1", $SQL);

0 comments on commit 13bbed3

Please sign in to comment.