1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 18:33:45 +01:00

- DibiFluent - added support for nested selects

- DibiFluent::__toString() returns NOT highlighted SQL
This commit is contained in:
David Grudl 2008-11-22 14:31:38 +00:00
parent fb2621eb04
commit 4b7b7de87a
2 changed files with 25 additions and 4 deletions

View File

@ -239,6 +239,26 @@ class DibiConnection extends DibiObject
/**
* Generates and returns SQL query.
* @param array|mixed one or more arguments
* @return string
* @throws DibiException
*/
final public function sql($args)
{
$args = func_get_args();
$this->connect();
$trans = new DibiTranslator($this->driver);
if ($trans->translate($args)) {
return $trans->sql;
} else {
throw new DibiException('SQL translate error: ' . $trans->sql);
}
}
/**
* Generates and prints SQL query.
* @param array|mixed one or more arguments

View File

@ -122,6 +122,9 @@ class DibiFluent extends DibiObject
} elseif (is_string($arg) && preg_match('#^[a-z][a-z0-9_.]*$#i', $arg)) { // identifier
$args = array('%n', $arg);
} elseif ($arg instanceof self) {
$args = array_merge(array('('), $arg->_export(), array(')'));
} elseif (is_array($arg)) { // any array
if (isset(self::$modifiers[$clause])) {
$args = array(self::$modifiers[$clause], $arg);
@ -383,14 +386,12 @@ class DibiFluent extends DibiObject
/**
* Returns (highlighted) SQL query.
* Returns SQL query.
* @return string
*/
final public function __toString()
{
ob_start();
$this->test();
return ob_get_clean();
return $this->connection->sql($this->_export());
}
}