2008-07-17 03:51:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2010-09-14 18:40:41 +02:00
|
|
|
* This file is part of the "dibi" - smart database abstraction layer.
|
2012-01-02 20:24:16 +01:00
|
|
|
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dibi SQL builder via fluent interfaces. EXPERIMENTAL!
|
|
|
|
*
|
2010-09-14 18:40:41 +02:00
|
|
|
* @author David Grudl
|
2012-01-03 04:50:11 +01:00
|
|
|
* @package dibi
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read string $command
|
|
|
|
* @property-read DibiConnection $connection
|
|
|
|
* @property-read DibiResultIterator $iterator
|
2010-04-23 14:55:29 +02:00
|
|
|
* @method DibiFluent select($field)
|
|
|
|
* @method DibiFluent distinct()
|
|
|
|
* @method DibiFluent from($table)
|
|
|
|
* @method DibiFluent where($cond)
|
|
|
|
* @method DibiFluent groupBy($field)
|
|
|
|
* @method DibiFluent having($cond)
|
|
|
|
* @method DibiFluent orderBy($field)
|
|
|
|
* @method DibiFluent limit(int $limit)
|
|
|
|
* @method DibiFluent offset(int $offset)
|
2014-09-16 08:58:25 +02:00
|
|
|
* @method DibiFluent leftJoin($table)
|
|
|
|
* @method DibiFluent on($cond)
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
2009-02-05 21:08:00 +00:00
|
|
|
class DibiFluent extends DibiObject implements IDataSource
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
2010-01-23 06:28:23 +01:00
|
|
|
const REMOVE = FALSE;
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/** @var array */
|
|
|
|
public static $masks = array(
|
|
|
|
'SELECT' => array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
2009-02-05 01:26:08 +00:00
|
|
|
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'),
|
|
|
|
'UPDATE' => array('UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'),
|
|
|
|
'INSERT' => array('INSERT', 'INTO', 'VALUES', 'SELECT'),
|
|
|
|
'DELETE' => array('DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'),
|
2008-07-17 03:51:29 +00:00
|
|
|
);
|
|
|
|
|
2009-02-05 01:26:08 +00:00
|
|
|
/** @var array default modifiers for arrays */
|
2008-10-25 00:26:56 +00:00
|
|
|
public static $modifiers = array(
|
2008-10-25 15:36:37 +00:00
|
|
|
'SELECT' => '%n',
|
2009-02-02 17:50:02 +00:00
|
|
|
'FROM' => '%n',
|
2010-01-23 05:25:17 +01:00
|
|
|
'IN' => '%in',
|
2008-10-25 00:26:56 +00:00
|
|
|
'VALUES' => '%l',
|
|
|
|
'SET' => '%a',
|
|
|
|
'WHERE' => '%and',
|
|
|
|
'HAVING' => '%and',
|
|
|
|
'ORDER BY' => '%by',
|
|
|
|
'GROUP BY' => '%by',
|
|
|
|
);
|
|
|
|
|
2009-02-05 01:26:08 +00:00
|
|
|
/** @var array clauses separators */
|
2008-07-17 03:51:29 +00:00
|
|
|
public static $separators = array(
|
|
|
|
'SELECT' => ',',
|
2010-08-03 21:54:01 +02:00
|
|
|
'FROM' => ',',
|
2008-07-17 03:51:29 +00:00
|
|
|
'WHERE' => 'AND',
|
|
|
|
'GROUP BY' => ',',
|
|
|
|
'HAVING' => 'AND',
|
|
|
|
'ORDER BY' => ',',
|
|
|
|
'LIMIT' => FALSE,
|
|
|
|
'OFFSET' => FALSE,
|
|
|
|
'SET' => ',',
|
|
|
|
'VALUES' => ',',
|
|
|
|
'INTO' => FALSE,
|
|
|
|
);
|
|
|
|
|
2010-05-19 16:38:51 +02:00
|
|
|
/** @var array clauses */
|
|
|
|
public static $clauseSwitches = array(
|
|
|
|
'JOIN' => 'FROM',
|
|
|
|
'INNER JOIN' => 'FROM',
|
|
|
|
'LEFT JOIN' => 'FROM',
|
|
|
|
'RIGHT JOIN' => 'FROM',
|
|
|
|
);
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/** @var DibiConnection */
|
|
|
|
private $connection;
|
|
|
|
|
2012-01-19 05:02:06 +01:00
|
|
|
/** @var array */
|
|
|
|
private $setups = array();
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/** @var string */
|
|
|
|
private $command;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $clauses = array();
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $flags = array();
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $cursor;
|
|
|
|
|
2011-01-25 18:00:29 +01:00
|
|
|
/** @var DibiHashMap normalized clauses */
|
2010-08-03 08:13:04 +02:00
|
|
|
private static $normalizer;
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param DibiConnection
|
|
|
|
*/
|
|
|
|
public function __construct(DibiConnection $connection)
|
|
|
|
{
|
|
|
|
$this->connection = $connection;
|
2010-08-03 08:13:04 +02:00
|
|
|
|
|
|
|
if (self::$normalizer === NULL) {
|
2011-01-25 18:00:29 +01:00
|
|
|
self::$normalizer = new DibiHashMap(array(__CLASS__, '_formatClause'));
|
2010-08-03 08:13:04 +02:00
|
|
|
}
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends new argument to the clause.
|
|
|
|
* @param string clause name
|
|
|
|
* @param array arguments
|
2013-07-02 18:42:55 +02:00
|
|
|
* @return self
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
|
|
|
public function __call($clause, $args)
|
|
|
|
{
|
2010-08-03 08:13:04 +02:00
|
|
|
$clause = self::$normalizer->$clause;
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
// lazy initialization
|
|
|
|
if ($this->command === NULL) {
|
|
|
|
if (isset(self::$masks[$clause])) {
|
|
|
|
$this->clauses = array_fill_keys(self::$masks[$clause], NULL);
|
|
|
|
}
|
|
|
|
$this->cursor = & $this->clauses[$clause];
|
|
|
|
$this->cursor = array();
|
|
|
|
$this->command = $clause;
|
|
|
|
}
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
// auto-switch to a clause
|
2010-05-19 16:38:51 +02:00
|
|
|
if (isset(self::$clauseSwitches[$clause])) {
|
|
|
|
$this->cursor = & $this->clauses[self::$clauseSwitches[$clause]];
|
|
|
|
}
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
if (array_key_exists($clause, $this->clauses)) {
|
|
|
|
// append to clause
|
|
|
|
$this->cursor = & $this->clauses[$clause];
|
|
|
|
|
|
|
|
// TODO: really delete?
|
2010-01-23 06:28:23 +01:00
|
|
|
if ($args === array(self::REMOVE)) {
|
2008-07-17 03:51:29 +00:00
|
|
|
$this->cursor = NULL;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset(self::$separators[$clause])) {
|
|
|
|
$sep = self::$separators[$clause];
|
2010-01-23 06:28:23 +01:00
|
|
|
if ($sep === FALSE) { // means: replace
|
2008-07-17 03:51:29 +00:00
|
|
|
$this->cursor = array();
|
|
|
|
|
|
|
|
} elseif (!empty($this->cursor)) {
|
|
|
|
$this->cursor[] = $sep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// append to currect flow
|
2010-01-23 06:28:23 +01:00
|
|
|
if ($args === array(self::REMOVE)) {
|
2008-07-17 03:51:29 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->cursor[] = $clause;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->cursor === NULL) {
|
|
|
|
$this->cursor = array();
|
|
|
|
}
|
|
|
|
|
2010-08-03 08:08:05 +02:00
|
|
|
// special types or argument
|
|
|
|
if (count($args) === 1) {
|
|
|
|
$arg = $args[0];
|
|
|
|
// TODO: really ignore TRUE?
|
|
|
|
if ($arg === TRUE) { // flag
|
|
|
|
return $this;
|
|
|
|
|
2012-10-18 22:06:19 +02:00
|
|
|
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
2010-08-03 08:08:05 +02:00
|
|
|
$args = array('%n', $arg);
|
|
|
|
|
2012-01-12 00:38:39 +01:00
|
|
|
} elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array
|
2010-08-03 08:08:05 +02:00
|
|
|
if (isset(self::$modifiers[$clause])) {
|
|
|
|
$args = array(self::$modifiers[$clause], $arg);
|
|
|
|
|
|
|
|
} elseif (is_string(key($arg))) { // associative array
|
|
|
|
$args = array('%a', $arg);
|
|
|
|
}
|
|
|
|
} // case $arg === FALSE is handled above
|
|
|
|
}
|
|
|
|
|
2012-01-12 00:38:39 +01:00
|
|
|
foreach ($args as $arg) {
|
|
|
|
if ($arg instanceof self) {
|
|
|
|
$arg = "($arg)";
|
|
|
|
}
|
|
|
|
$this->cursor[] = $arg;
|
|
|
|
}
|
2010-08-03 08:13:04 +02:00
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch to a clause.
|
|
|
|
* @param string clause name
|
2013-07-02 18:42:55 +02:00
|
|
|
* @return self
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
2014-06-02 16:28:38 +02:00
|
|
|
public function clause($clause)
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
2010-08-03 08:13:04 +02:00
|
|
|
$this->cursor = & $this->clauses[self::$normalizer->$clause];
|
2014-06-02 16:28:38 +02:00
|
|
|
if ($this->cursor === NULL) {
|
2008-07-17 03:51:29 +00:00
|
|
|
$this->cursor = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-23 04:43:36 +01:00
|
|
|
/**
|
|
|
|
* Removes a clause.
|
|
|
|
* @param string clause name
|
2013-07-02 18:42:55 +02:00
|
|
|
* @return self
|
2010-01-23 04:43:36 +01:00
|
|
|
*/
|
|
|
|
public function removeClause($clause)
|
|
|
|
{
|
2010-08-03 08:13:04 +02:00
|
|
|
$this->clauses[self::$normalizer->$clause] = NULL;
|
2010-01-23 04:43:36 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/**
|
|
|
|
* Change a SQL flag.
|
|
|
|
* @param string flag name
|
|
|
|
* @param bool value
|
2013-07-02 18:42:55 +02:00
|
|
|
* @return self
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
|
|
|
public function setFlag($flag, $value = TRUE)
|
|
|
|
{
|
|
|
|
$flag = strtoupper($flag);
|
|
|
|
if ($value) {
|
|
|
|
$this->flags[$flag] = TRUE;
|
|
|
|
} else {
|
|
|
|
unset($this->flags[$flag]);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is a flag set?
|
|
|
|
* @param string flag name
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-10-28 01:03:50 +00:00
|
|
|
final public function getFlag($flag)
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
|
|
|
return isset($this->flags[strtoupper($flag)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns SQL command.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
final public function getCommand()
|
|
|
|
{
|
|
|
|
return $this->command;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-23 03:55:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the dibi connection.
|
|
|
|
* @return DibiConnection
|
|
|
|
*/
|
|
|
|
final public function getConnection()
|
|
|
|
{
|
|
|
|
return $this->connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-19 05:02:06 +01:00
|
|
|
/**
|
|
|
|
* Adds DibiResult setup.
|
|
|
|
* @param string method
|
|
|
|
* @param mixed args
|
2013-07-02 18:42:55 +02:00
|
|
|
* @return self
|
2012-01-19 05:02:06 +01:00
|
|
|
*/
|
|
|
|
public function setupResult($method)
|
|
|
|
{
|
|
|
|
$this->setups[] = func_get_args();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-23 03:55:47 +00:00
|
|
|
/********************* executing ****************d*g**/
|
|
|
|
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/**
|
|
|
|
* Generates and executes SQL query.
|
2009-02-05 02:13:15 +00:00
|
|
|
* @param mixed what to return?
|
|
|
|
* @return DibiResult|int result set object (if any)
|
2008-07-17 03:51:29 +00:00
|
|
|
* @throws DibiException
|
|
|
|
*/
|
2009-02-05 02:13:15 +00:00
|
|
|
public function execute($return = NULL)
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
2012-01-19 05:02:06 +01:00
|
|
|
$res = $this->query($this->_export());
|
2013-05-15 14:14:42 +03:00
|
|
|
switch ($return) {
|
|
|
|
case dibi::IDENTIFIER:
|
|
|
|
return $this->connection->getInsertId();
|
|
|
|
case dibi::AFFECTED_ROWS:
|
|
|
|
return $this->connection->getAffectedRows();
|
|
|
|
default:
|
|
|
|
return $res;
|
|
|
|
}
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates, executes SQL query and fetches the single row.
|
2008-10-10 17:39:33 +00:00
|
|
|
* @return DibiRow|FALSE array on success, FALSE if no next record
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
|
|
|
public function fetch()
|
|
|
|
{
|
|
|
|
if ($this->command === 'SELECT') {
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetch();
|
2009-02-05 01:26:08 +00:00
|
|
|
} else {
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export())->fetch();
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-11 12:33:49 +00:00
|
|
|
/**
|
|
|
|
* Like fetch(), but returns only first field.
|
|
|
|
* @return mixed value on success, FALSE if no next record
|
|
|
|
*/
|
|
|
|
public function fetchSingle()
|
|
|
|
{
|
|
|
|
if ($this->command === 'SELECT') {
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetchSingle();
|
2009-02-05 01:26:08 +00:00
|
|
|
} else {
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export())->fetchSingle();
|
2008-09-11 12:33:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all records from table.
|
|
|
|
* @param int offset
|
|
|
|
* @param int limit
|
|
|
|
* @return array
|
|
|
|
*/
|
2008-10-01 16:04:16 +00:00
|
|
|
public function fetchAll($offset = NULL, $limit = NULL)
|
2008-09-11 12:33:49 +00:00
|
|
|
{
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export(NULL, array('%ofs %lmt', $offset, $limit)))->fetchAll();
|
2008-09-11 12:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all records from table and returns associative tree.
|
|
|
|
* @param string associative descriptor
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fetchAssoc($assoc)
|
|
|
|
{
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export())->fetchAssoc($assoc);
|
2008-09-11 12:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all records from table like $key => $value pairs.
|
|
|
|
* @param string associative key
|
|
|
|
* @param string value
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fetchPairs($key = NULL, $value = NULL)
|
|
|
|
{
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export())->fetchPairs($key, $value);
|
2009-02-05 01:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required by the IteratorAggregate interface.
|
|
|
|
* @param int offset
|
|
|
|
* @param int limit
|
|
|
|
* @return DibiResultIterator
|
|
|
|
*/
|
|
|
|
public function getIterator($offset = NULL, $limit = NULL)
|
|
|
|
{
|
2012-01-19 05:02:06 +01:00
|
|
|
return $this->query($this->_export(NULL, array('%ofs %lmt', $offset, $limit)))->getIterator();
|
2009-02-05 01:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-23 03:55:47 +00:00
|
|
|
/**
|
|
|
|
* Generates and prints SQL query or it's part.
|
|
|
|
* @param string clause name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function test($clause = NULL)
|
|
|
|
{
|
|
|
|
return $this->connection->test($this->_export($clause));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-05 01:26:08 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function count()
|
|
|
|
{
|
2012-01-19 05:02:06 +01:00
|
|
|
return (int) $this->query(array(
|
2009-02-05 01:26:08 +00:00
|
|
|
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]'
|
2012-01-19 05:02:06 +01:00
|
|
|
))->fetchSingle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DibiResult
|
|
|
|
*/
|
|
|
|
private function query($args)
|
|
|
|
{
|
|
|
|
$res = $this->connection->query($args);
|
|
|
|
foreach ($this->setups as $setup) {
|
|
|
|
call_user_func_array(array($res, array_shift($setup)), $setup);
|
|
|
|
}
|
|
|
|
return $res;
|
2008-09-11 12:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-23 03:55:47 +00:00
|
|
|
/********************* exporting ****************d*g**/
|
|
|
|
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/**
|
2009-02-23 03:55:47 +00:00
|
|
|
* @return DibiDataSource
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
2009-02-23 03:55:47 +00:00
|
|
|
public function toDataSource()
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
2010-08-04 12:10:29 +02:00
|
|
|
return new DibiDataSource($this->connection->translate($this->_export()), $this->connection);
|
2009-02-23 03:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns SQL query.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
final public function __toString()
|
|
|
|
{
|
2012-01-19 02:25:30 +01:00
|
|
|
try {
|
|
|
|
return $this->connection->translate($this->_export());
|
|
|
|
} catch (Exception $e) {
|
|
|
|
trigger_error($e->getMessage(), E_USER_ERROR);
|
|
|
|
}
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates parameters for DibiTranslator.
|
|
|
|
* @param string clause name
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-02-05 01:26:08 +00:00
|
|
|
protected function _export($clause = NULL, $args = array())
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
|
|
|
if ($clause === NULL) {
|
|
|
|
$data = $this->clauses;
|
|
|
|
|
|
|
|
} else {
|
2010-08-03 08:13:04 +02:00
|
|
|
$clause = self::$normalizer->$clause;
|
2008-07-17 03:51:29 +00:00
|
|
|
if (array_key_exists($clause, $this->clauses)) {
|
|
|
|
$data = array($clause => $this->clauses[$clause]);
|
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($data as $clause => $statement) {
|
|
|
|
if ($statement !== NULL) {
|
2009-02-05 01:26:08 +00:00
|
|
|
$args[] = $clause;
|
2010-08-03 08:13:04 +02:00
|
|
|
if ($clause === $this->command && $this->flags) {
|
2009-02-05 01:26:08 +00:00
|
|
|
$args[] = implode(' ', array_keys($this->flags));
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
2013-07-02 18:42:55 +02:00
|
|
|
foreach ($statement as $arg) {
|
|
|
|
$args[] = $arg;
|
|
|
|
}
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-05 01:26:08 +00:00
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format camelCase clause name to UPPER CASE.
|
|
|
|
* @param string
|
|
|
|
* @return string
|
2010-08-03 22:48:44 +02:00
|
|
|
* @internal
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
2010-08-03 08:13:04 +02:00
|
|
|
public static function _formatClause($s)
|
2008-07-17 03:51:29 +00:00
|
|
|
{
|
|
|
|
if ($s === 'order' || $s === 'group') {
|
|
|
|
$s .= 'By';
|
|
|
|
trigger_error("Did you mean '$s'?", E_USER_NOTICE);
|
|
|
|
}
|
2010-01-24 18:58:05 +01:00
|
|
|
return strtoupper(preg_replace('#[a-z](?=[A-Z])#', '$0 ', $s));
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
2010-01-24 18:57:04 +01:00
|
|
|
|
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
// remove references
|
|
|
|
foreach ($this->clauses as $clause => $val) {
|
|
|
|
$this->clauses[$clause] = & $val;
|
2010-01-26 19:55:00 +01:00
|
|
|
unset($val);
|
2010-01-24 18:57:04 +01:00
|
|
|
}
|
|
|
|
$this->cursor = & $foo;
|
|
|
|
}
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
}
|