You've already forked joomla_test
first commit
This commit is contained in:
1
libraries/joomla/database/query/index.html
Normal file
1
libraries/joomla/database/query/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
56
libraries/joomla/database/query/limitable.php
Normal file
56
libraries/joomla/database/query/limitable.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla Database Query Limitable Interface.
|
||||
* Adds bind/unbind methods as well as a getBounded() method
|
||||
* to retrieve the stored bounded variables on demand prior to
|
||||
* query execution.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 12.1
|
||||
*/
|
||||
interface JDatabaseQueryLimitable
|
||||
{
|
||||
/**
|
||||
* Method to modify a query already in string format with the needed
|
||||
* additions to make the query limited to a particular number of
|
||||
* results, or start at a particular offset. This method is used
|
||||
* automatically by the __toString() method if it detects that the
|
||||
* query implements the JDatabaseQueryLimitable interface.
|
||||
*
|
||||
* @param string $query The query in string format
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function processLimit($query, $limit, $offset = 0);
|
||||
|
||||
/**
|
||||
* Sets the offset and limit for the result set, if the database driver supports it.
|
||||
*
|
||||
* Usage:
|
||||
* $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
|
||||
* $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
|
||||
*
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function setLimit($limit = 0, $offset = 0);
|
||||
}
|
21
libraries/joomla/database/query/mysql.php
Normal file
21
libraries/joomla/database/query/mysql.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 11.1
|
||||
*/
|
||||
class JDatabaseQueryMysql extends JDatabaseQueryMysqli
|
||||
{
|
||||
}
|
106
libraries/joomla/database/query/mysqli.php
Normal file
106
libraries/joomla/database/query/mysqli.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 11.1
|
||||
*/
|
||||
class JDatabaseQueryMysqli extends JDatabaseQuery implements JDatabaseQueryLimitable
|
||||
{
|
||||
/**
|
||||
* @var interger The offset for the result set.
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $offset;
|
||||
|
||||
/**
|
||||
* @var integer The limit for the result set.
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $limit;
|
||||
|
||||
/**
|
||||
* Method to modify a query already in string format with the needed
|
||||
* additions to make the query limited to a particular number of
|
||||
* results, or start at a particular offset.
|
||||
*
|
||||
* @param string $query The query in string format
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function processLimit($query, $limit, $offset = 0)
|
||||
{
|
||||
if ($limit > 0 || $offset > 0)
|
||||
{
|
||||
$query .= ' LIMIT ' . $offset . ', ' . $limit;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates an array of column names or values.
|
||||
*
|
||||
* @param array $values An array of values to concatenate.
|
||||
* @param string $separator As separator to place between each value.
|
||||
*
|
||||
* @return string The concatenated values.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function concatenate($values, $separator = null)
|
||||
{
|
||||
if ($separator)
|
||||
{
|
||||
$concat_string = 'CONCAT_WS(' . $this->quote($separator);
|
||||
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$concat_string .= ', ' . $value;
|
||||
}
|
||||
|
||||
return $concat_string . ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'CONCAT(' . implode(',', $values) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset and limit for the result set, if the database driver supports it.
|
||||
*
|
||||
* Usage:
|
||||
* $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
|
||||
* $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
|
||||
*
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function setLimit($limit = 0, $offset = 0)
|
||||
{
|
||||
$this->limit = (int) $limit;
|
||||
$this->offset = (int) $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
204
libraries/joomla/database/query/oracle.php
Normal file
204
libraries/joomla/database/query/oracle.php
Normal file
@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Oracle Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 12.1
|
||||
*/
|
||||
class JDatabaseQueryOracle extends JDatabaseQueryPdo implements JDatabaseQueryPreparable, JDatabaseQueryLimitable
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $limit;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $offset;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $bounded = array();
|
||||
|
||||
/**
|
||||
* Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
|
||||
* removes a variable that has been bounded from the internal bounded array when the passed in value is null.
|
||||
*
|
||||
* @param string|integer $key The key that will be used in your SQL query to reference the value. Usually of
|
||||
* the form ':key', but can also be an integer.
|
||||
* @param mixed &$value The value that will be bound. The value is passed by reference to support output
|
||||
* parameters such as those possible with stored procedures.
|
||||
* @param integer $dataType Constant corresponding to a SQL datatype.
|
||||
* @param integer $length The length of the variable. Usually required for OUTPUT parameters.
|
||||
* @param array $driverOptions Optional driver options to be used.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
|
||||
{
|
||||
// Case 1: Empty Key (reset $bounded array)
|
||||
if (empty($key))
|
||||
{
|
||||
$this->bounded = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Case 2: Key Provided, null value (unset key from $bounded array)
|
||||
if (is_null($value))
|
||||
{
|
||||
if (isset($this->bounded[$key]))
|
||||
{
|
||||
unset($this->bounded[$key]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$obj = new stdClass;
|
||||
|
||||
$obj->value = &$value;
|
||||
$obj->dataType = $dataType;
|
||||
$obj->length = $length;
|
||||
$obj->driverOptions = $driverOptions;
|
||||
|
||||
// Case 3: Simply add the Key/Value into the bounded array
|
||||
$this->bounded[$key] = $obj;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
|
||||
* returned.
|
||||
*
|
||||
* @param mixed $key The bounded variable key to retrieve.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function &getBounded($key = null)
|
||||
{
|
||||
if (empty($key))
|
||||
{
|
||||
return $this->bounded;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($this->bounded[$key]))
|
||||
{
|
||||
return $this->bounded[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear data from the query or a specific clause of the query.
|
||||
*
|
||||
* @param string $clause Optionally, the name of the clause to clear, or nothing to clear the whole query.
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function clear($clause = null)
|
||||
{
|
||||
switch ($clause)
|
||||
{
|
||||
case null:
|
||||
$this->bounded = array();
|
||||
break;
|
||||
}
|
||||
|
||||
parent::clear($clause);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to modify a query already in string format with the needed
|
||||
* additions to make the query limited to a particular number of
|
||||
* results, or start at a particular offset. This method is used
|
||||
* automatically by the __toString() method if it detects that the
|
||||
* query implements the JDatabaseQueryLimitable interface.
|
||||
*
|
||||
* @param string $query The query in string format
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function processLimit($query, $limit, $offset = 0)
|
||||
{
|
||||
// Check if we need to mangle the query.
|
||||
if ($limit || $offset)
|
||||
{
|
||||
$query = "SELECT joomla2.*
|
||||
FROM (
|
||||
SELECT joomla1.*, ROWNUM AS joomla_db_rownum
|
||||
FROM (
|
||||
" . $query . "
|
||||
) joomla1
|
||||
) joomla2";
|
||||
|
||||
// Check if the limit value is greater than zero.
|
||||
if ($limit > 0)
|
||||
{
|
||||
$query .= ' WHERE joomla2.joomla_db_rownum BETWEEN ' . ($offset + 1) . ' AND ' . ($offset + $limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if there is an offset and then use this.
|
||||
if ($offset)
|
||||
{
|
||||
$query .= ' WHERE joomla2.joomla_db_rownum > ' . ($offset + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset and limit for the result set, if the database driver supports it.
|
||||
*
|
||||
* Usage:
|
||||
* $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
|
||||
* $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
|
||||
*
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function setLimit($limit = 0, $offset = 0)
|
||||
{
|
||||
$this->limit = (int) $limit;
|
||||
$this->offset = (int) $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
21
libraries/joomla/database/query/pdo.php
Normal file
21
libraries/joomla/database/query/pdo.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* PDO Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 12.1
|
||||
*/
|
||||
class JDatabaseQueryPdo extends JDatabaseQuery
|
||||
{
|
||||
}
|
630
libraries/joomla/database/query/postgresql.php
Normal file
630
libraries/joomla/database/query/postgresql.php
Normal file
@ -0,0 +1,630 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 11.3
|
||||
*/
|
||||
class JDatabaseQueryPostgresql extends JDatabaseQuery implements JDatabaseQueryLimitable
|
||||
{
|
||||
/**
|
||||
* @var object The FOR UPDATE element used in "FOR UPDATE" lock
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $forUpdate = null;
|
||||
|
||||
/**
|
||||
* @var object The FOR SHARE element used in "FOR SHARE" lock
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $forShare = null;
|
||||
|
||||
/**
|
||||
* @var object The NOWAIT element used in "FOR SHARE" and "FOR UPDATE" lock
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $noWait = null;
|
||||
|
||||
/**
|
||||
* @var object The LIMIT element
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $limit = null;
|
||||
|
||||
/**
|
||||
* @var object The OFFSET element
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $offset = null;
|
||||
|
||||
/**
|
||||
* @var object The RETURNING element of INSERT INTO
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $returning = null;
|
||||
|
||||
/**
|
||||
* Magic function to convert the query to a string, only for postgresql specific query
|
||||
*
|
||||
* @return string The completed query.
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$query = '';
|
||||
|
||||
switch ($this->type)
|
||||
{
|
||||
case 'select':
|
||||
$query .= (string) $this->select;
|
||||
$query .= (string) $this->from;
|
||||
|
||||
if ($this->join)
|
||||
{
|
||||
// Special case for joins
|
||||
foreach ($this->join as $join)
|
||||
{
|
||||
$query .= (string) $join;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->where)
|
||||
{
|
||||
$query .= (string) $this->where;
|
||||
}
|
||||
|
||||
if ($this->group)
|
||||
{
|
||||
$query .= (string) $this->group;
|
||||
}
|
||||
|
||||
if ($this->having)
|
||||
{
|
||||
$query .= (string) $this->having;
|
||||
}
|
||||
|
||||
if ($this->order)
|
||||
{
|
||||
$query .= (string) $this->order;
|
||||
}
|
||||
|
||||
if ($this->limit)
|
||||
{
|
||||
$query .= (string) $this->limit;
|
||||
}
|
||||
|
||||
if ($this->offset)
|
||||
{
|
||||
$query .= (string) $this->offset;
|
||||
}
|
||||
|
||||
if ($this->forUpdate)
|
||||
{
|
||||
$query .= (string) $this->forUpdate;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->forShare)
|
||||
{
|
||||
$query .= (string) $this->forShare;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->noWait)
|
||||
{
|
||||
$query .= (string) $this->noWait;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$query .= (string) $this->update;
|
||||
$query .= (string) $this->set;
|
||||
|
||||
if ($this->join)
|
||||
{
|
||||
$onWord = ' ON ';
|
||||
|
||||
// Workaround for special case of JOIN with UPDATE
|
||||
foreach ($this->join as $join)
|
||||
{
|
||||
$joinElem = $join->getElements();
|
||||
|
||||
$joinArray = explode($onWord, $joinElem[0]);
|
||||
|
||||
$this->from($joinArray[0]);
|
||||
$this->where($joinArray[1]);
|
||||
}
|
||||
|
||||
$query .= (string) $this->from;
|
||||
}
|
||||
|
||||
if ($this->where)
|
||||
{
|
||||
$query .= (string) $this->where;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'insert':
|
||||
$query .= (string) $this->insert;
|
||||
|
||||
if ($this->values)
|
||||
{
|
||||
if ($this->columns)
|
||||
{
|
||||
$query .= (string) $this->columns;
|
||||
}
|
||||
|
||||
$elements = $this->values->getElements();
|
||||
|
||||
if (!($elements[0] instanceof $this))
|
||||
{
|
||||
$query .= ' VALUES ';
|
||||
}
|
||||
|
||||
$query .= (string) $this->values;
|
||||
|
||||
if ($this->returning)
|
||||
{
|
||||
$query .= (string) $this->returning;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$query = parent::__toString();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear data from the query or a specific clause of the query.
|
||||
*
|
||||
* @param string $clause Optionally, the name of the clause to clear, or nothing to clear the whole query.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function clear($clause = null)
|
||||
{
|
||||
switch ($clause)
|
||||
{
|
||||
case 'limit':
|
||||
$this->limit = null;
|
||||
break;
|
||||
|
||||
case 'offset':
|
||||
$this->offset = null;
|
||||
break;
|
||||
|
||||
case 'forUpdate':
|
||||
$this->forUpdate = null;
|
||||
break;
|
||||
|
||||
case 'forShare':
|
||||
$this->forShare = null;
|
||||
break;
|
||||
|
||||
case 'noWait':
|
||||
$this->noWait = null;
|
||||
break;
|
||||
|
||||
case 'returning':
|
||||
$this->returning = null;
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
case 'update':
|
||||
case 'delete':
|
||||
case 'insert':
|
||||
case 'from':
|
||||
case 'join':
|
||||
case 'set':
|
||||
case 'where':
|
||||
case 'group':
|
||||
case 'having':
|
||||
case 'order':
|
||||
case 'columns':
|
||||
case 'values':
|
||||
parent::clear($clause);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->type = null;
|
||||
$this->limit = null;
|
||||
$this->offset = null;
|
||||
$this->forUpdate = null;
|
||||
$this->forShare = null;
|
||||
$this->noWait = null;
|
||||
$this->returning = null;
|
||||
parent::clear($clause);
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a value to a char.
|
||||
*
|
||||
* Ensure that the value is properly quoted before passing to the method.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->castAsChar('a'));
|
||||
*
|
||||
* @param string $value The value to cast as a char.
|
||||
*
|
||||
* @return string Returns the cast value.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function castAsChar($value)
|
||||
{
|
||||
return $value . '::text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates an array of column names or values.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->concatenate(array('a', 'b')));
|
||||
*
|
||||
* @param array $values An array of values to concatenate.
|
||||
* @param string $separator As separator to place between each value.
|
||||
*
|
||||
* @return string The concatenated values.
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function concatenate($values, $separator = null)
|
||||
{
|
||||
if ($separator)
|
||||
{
|
||||
return implode(' || ' . $this->quote($separator) . ' || ', $values);
|
||||
}
|
||||
else
|
||||
{
|
||||
return implode(' || ', $values);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current date and time.
|
||||
*
|
||||
* @return string Return string used in query to obtain
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function currentTimestamp()
|
||||
{
|
||||
return 'NOW()';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the FOR UPDATE lock on select's output row
|
||||
*
|
||||
* @param string $table_name The table to lock
|
||||
* @param boolean $glue The glue by which to join the conditions. Defaults to ',' .
|
||||
*
|
||||
* @return JDatabaseQuery FOR UPDATE query element
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function forUpdate ($table_name, $glue = ',')
|
||||
{
|
||||
$this->type = 'forUpdate';
|
||||
|
||||
if ( is_null($this->forUpdate) )
|
||||
{
|
||||
$glue = strtoupper($glue);
|
||||
$this->forUpdate = new JDatabaseQueryElement('FOR UPDATE', 'OF ' . $table_name, "$glue ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->forUpdate->append($table_name);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the FOR SHARE lock on select's output row
|
||||
*
|
||||
* @param string $table_name The table to lock
|
||||
* @param boolean $glue The glue by which to join the conditions. Defaults to ',' .
|
||||
*
|
||||
* @return JDatabaseQuery FOR SHARE query element
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function forShare ($table_name, $glue = ',')
|
||||
{
|
||||
$this->type = 'forShare';
|
||||
|
||||
if ( is_null($this->forShare) )
|
||||
{
|
||||
$glue = strtoupper($glue);
|
||||
$this->forShare = new JDatabaseQueryElement('FOR SHARE', 'OF ' . $table_name, "$glue ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->forShare->append($table_name);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string to extract year from date column.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->year($query->quoteName('dateColumn')));
|
||||
*
|
||||
* @param string $date Date column containing year to be extracted.
|
||||
*
|
||||
* @return string Returns string to extract year from a date.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function year($date)
|
||||
{
|
||||
return 'EXTRACT (YEAR FROM ' . $date . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string to extract month from date column.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->month($query->quoteName('dateColumn')));
|
||||
*
|
||||
* @param string $date Date column containing month to be extracted.
|
||||
*
|
||||
* @return string Returns string to extract month from a date.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function month($date)
|
||||
{
|
||||
return 'EXTRACT (MONTH FROM ' . $date . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string to extract day from date column.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->day($query->quoteName('dateColumn')));
|
||||
*
|
||||
* @param string $date Date column containing day to be extracted.
|
||||
*
|
||||
* @return string Returns string to extract day from a date.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function day($date)
|
||||
{
|
||||
return 'EXTRACT (DAY FROM ' . $date . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string to extract hour from date column.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->hour($query->quoteName('dateColumn')));
|
||||
*
|
||||
* @param string $date Date column containing hour to be extracted.
|
||||
*
|
||||
* @return string Returns string to extract hour from a date.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function hour($date)
|
||||
{
|
||||
return 'EXTRACT (HOUR FROM ' . $date . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string to extract minute from date column.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->minute($query->quoteName('dateColumn')));
|
||||
*
|
||||
* @param string $date Date column containing minute to be extracted.
|
||||
*
|
||||
* @return string Returns string to extract minute from a date.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function minute($date)
|
||||
{
|
||||
return 'EXTRACT (MINUTE FROM ' . $date . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string to extract seconds from date column.
|
||||
*
|
||||
* Usage:
|
||||
* $query->select($query->second($query->quoteName('dateColumn')));
|
||||
*
|
||||
* @param string $date Date column containing second to be extracted.
|
||||
*
|
||||
* @return string Returns string to extract second from a date.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function second($date)
|
||||
{
|
||||
return 'EXTRACT (SECOND FROM ' . $date . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NOWAIT lock on select's output row
|
||||
*
|
||||
* @return JDatabaseQuery NO WAIT query element
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function noWait ()
|
||||
{
|
||||
$this->type = 'noWait';
|
||||
|
||||
if ( is_null($this->noWait) )
|
||||
{
|
||||
$this->noWait = new JDatabaseQueryElement('NOWAIT', null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the LIMIT clause to the query
|
||||
*
|
||||
* @param int $limit An int of how many row will be returned
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function limit( $limit = 0 )
|
||||
{
|
||||
if (is_null($this->limit))
|
||||
{
|
||||
$this->limit = new JDatabaseQueryElement('LIMIT', (int) $limit);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OFFSET clause to the query
|
||||
*
|
||||
* @param int $offset An int for skipping row
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function offset( $offset = 0 )
|
||||
{
|
||||
if (is_null($this->offset))
|
||||
{
|
||||
$this->offset = new JDatabaseQueryElement('OFFSET', (int) $offset);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the RETURNING element to INSERT INTO statement.
|
||||
*
|
||||
* @param mixed $pkCol The name of the primary key column.
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 11.3
|
||||
*/
|
||||
public function returning( $pkCol )
|
||||
{
|
||||
if (is_null($this->returning))
|
||||
{
|
||||
$this->returning = new JDatabaseQueryElement('RETURNING', $pkCol);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset and limit for the result set, if the database driver supports it.
|
||||
*
|
||||
* Usage:
|
||||
* $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
|
||||
* $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
|
||||
*
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function setLimit($limit = 0, $offset = 0)
|
||||
{
|
||||
$this->limit = (int) $limit;
|
||||
$this->offset = (int) $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to modify a query already in string format with the needed
|
||||
* additions to make the query limited to a particular number of
|
||||
* results, or start at a particular offset.
|
||||
*
|
||||
* @param string $query The query in string format
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function processLimit($query, $limit, $offset = 0)
|
||||
{
|
||||
if ($limit > 0)
|
||||
{
|
||||
$query .= ' LIMIT ' . $limit;
|
||||
}
|
||||
|
||||
if ($offset > 0)
|
||||
{
|
||||
$query .= ' OFFSET ' . $offset;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to the current date and time in Postgresql.
|
||||
* Usage:
|
||||
* $query->select($query->dateAdd());
|
||||
* Prefixing the interval with a - (negative sign) will cause subtraction to be used.
|
||||
*
|
||||
* @param datetime $date The date to add to
|
||||
* @param string $interval The string representation of the appropriate number of units
|
||||
* @param string $datePart The part of the date to perform the addition on
|
||||
*
|
||||
* @return string The string with the appropriate sql for addition of dates
|
||||
*
|
||||
* @since 13.1
|
||||
* @note Not all drivers support all units. Check appropriate references
|
||||
* @link http://www.postgresql.org/docs/9.0/static/functions-datetime.html.
|
||||
*/
|
||||
public function dateAdd($date, $interval, $datePart)
|
||||
{
|
||||
if (substr($interval, 0, 1) != '-')
|
||||
{
|
||||
return "timestamp '" . $date . "' + interval '" . $interval . " " . $datePart . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "timestamp '" . $date . "' - interval '" . ltrim($interval, '-') . " " . $datePart . "'";
|
||||
}
|
||||
}
|
||||
}
|
53
libraries/joomla/database/query/preparable.php
Normal file
53
libraries/joomla/database/query/preparable.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla Database Query Preparable Interface.
|
||||
* Adds bind/unbind methods as well as a getBounded() method
|
||||
* to retrieve the stored bounded variables on demand prior to
|
||||
* query execution.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 12.1
|
||||
*/
|
||||
interface JDatabaseQueryPreparable
|
||||
{
|
||||
/**
|
||||
* Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
|
||||
* removes a variable that has been bounded from the internal bounded array when the passed in value is null.
|
||||
*
|
||||
* @param string|integer $key The key that will be used in your SQL query to reference the value. Usually of
|
||||
* the form ':key', but can also be an integer.
|
||||
* @param mixed &$value The value that will be bound. The value is passed by reference to support output
|
||||
* parameters such as those possible with stored procedures.
|
||||
* @param integer $dataType Constant corresponding to a SQL datatype.
|
||||
* @param integer $length The length of the variable. Usually required for OUTPUT parameters.
|
||||
* @param array $driverOptions Optional driver options to be used.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array());
|
||||
|
||||
/**
|
||||
* Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
|
||||
* returned.
|
||||
*
|
||||
* @param mixed $key The bounded variable key to retrieve.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function &getBounded($key = null);
|
||||
}
|
32
libraries/joomla/database/query/sqlazure.php
Normal file
32
libraries/joomla/database/query/sqlazure.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 11.1
|
||||
*/
|
||||
class JDatabaseQuerySqlazure extends JDatabaseQuerySqlsrv
|
||||
{
|
||||
/**
|
||||
* The character(s) used to quote SQL statement names such as table names or field names,
|
||||
* etc. The child classes should define this as necessary. If a single character string the
|
||||
* same character is used for both sides of the quoted name, else the first character will be
|
||||
* used for the opening quote and the second for the closing quote.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $name_quotes = '';
|
||||
}
|
217
libraries/joomla/database/query/sqlite.php
Normal file
217
libraries/joomla/database/query/sqlite.php
Normal file
@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* SQLite Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 12.1
|
||||
*/
|
||||
class JDatabaseQuerySqlite extends JDatabaseQueryPdo implements JDatabaseQueryPreparable, JDatabaseQueryLimitable
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $limit;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $offset;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $bounded = array();
|
||||
|
||||
/**
|
||||
* Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
|
||||
* removes a variable that has been bounded from the internal bounded array when the passed in value is null.
|
||||
*
|
||||
* @param string|integer $key The key that will be used in your SQL query to reference the value. Usually of
|
||||
* the form ':key', but can also be an integer.
|
||||
* @param mixed &$value The value that will be bound. The value is passed by reference to support output
|
||||
* parameters such as those possible with stored procedures.
|
||||
* @param integer $dataType Constant corresponding to a SQL datatype.
|
||||
* @param integer $length The length of the variable. Usually required for OUTPUT parameters.
|
||||
* @param array $driverOptions Optional driver options to be used.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
|
||||
{
|
||||
// Case 1: Empty Key (reset $bounded array)
|
||||
if (empty($key))
|
||||
{
|
||||
$this->bounded = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Case 2: Key Provided, null value (unset key from $bounded array)
|
||||
if (is_null($value))
|
||||
{
|
||||
if (isset($this->bounded[$key]))
|
||||
{
|
||||
unset($this->bounded[$key]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$obj = new stdClass;
|
||||
|
||||
$obj->value = &$value;
|
||||
$obj->dataType = $dataType;
|
||||
$obj->length = $length;
|
||||
$obj->driverOptions = $driverOptions;
|
||||
|
||||
// Case 3: Simply add the Key/Value into the bounded array
|
||||
$this->bounded[$key] = $obj;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
|
||||
* returned.
|
||||
*
|
||||
* @param mixed $key The bounded variable key to retrieve.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function &getBounded($key = null)
|
||||
{
|
||||
if (empty($key))
|
||||
{
|
||||
return $this->bounded;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($this->bounded[$key]))
|
||||
{
|
||||
return $this->bounded[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear data from the query or a specific clause of the query.
|
||||
*
|
||||
* @param string $clause Optionally, the name of the clause to clear, or nothing to clear the whole query.
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function clear($clause = null)
|
||||
{
|
||||
switch ($clause)
|
||||
{
|
||||
case null:
|
||||
$this->bounded = array();
|
||||
break;
|
||||
}
|
||||
|
||||
parent::clear($clause);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to modify a query already in string format with the needed
|
||||
* additions to make the query limited to a particular number of
|
||||
* results, or start at a particular offset. This method is used
|
||||
* automatically by the __toString() method if it detects that the
|
||||
* query implements the JDatabaseQueryLimitable interface.
|
||||
*
|
||||
* @param string $query The query in string format
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function processLimit($query, $limit, $offset = 0)
|
||||
{
|
||||
if ($limit > 0 || $offset > 0)
|
||||
{
|
||||
$query .= ' LIMIT ' . $offset . ', ' . $limit;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset and limit for the result set, if the database driver supports it.
|
||||
*
|
||||
* Usage:
|
||||
* $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
|
||||
* $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
|
||||
*
|
||||
* @param integer $limit The limit for the result set
|
||||
* @param integer $offset The offset for the result set
|
||||
*
|
||||
* @return JDatabaseQuery Returns this object to allow chaining.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function setLimit($limit = 0, $offset = 0)
|
||||
{
|
||||
$this->limit = (int) $limit;
|
||||
$this->offset = (int) $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to the current date and time.
|
||||
* Usage:
|
||||
* $query->select($query->dateAdd());
|
||||
* Prefixing the interval with a - (negative sign) will cause subtraction to be used.
|
||||
*
|
||||
* @param datetime $date The date or datetime to add to
|
||||
* @param string $interval The string representation of the appropriate number of units
|
||||
* @param string $datePart The part of the date to perform the addition on
|
||||
*
|
||||
* @return string The string with the appropriate sql for addition of dates
|
||||
*
|
||||
* @since 13.1
|
||||
* @link http://www.sqlite.org/lang_datefunc.html
|
||||
*/
|
||||
public function dateAdd($date, $interval, $datePart)
|
||||
{
|
||||
// SQLite does not support microseconds as a separate unit. Convert the interval to seconds
|
||||
if (strcasecmp($datePart, 'microseconds') == 0)
|
||||
{
|
||||
$interval = .001 * $interval;
|
||||
$datePart = 'seconds';
|
||||
}
|
||||
|
||||
if (substr($interval, 0, 1) != '-')
|
||||
{
|
||||
return "datetime('" . $date . "', '+" . $interval . " " . $datePart . "')";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "datetime('" . $date . "', '" . $interval . " " . $datePart . "')";
|
||||
}
|
||||
}
|
||||
}
|
199
libraries/joomla/database/query/sqlsrv.php
Normal file
199
libraries/joomla/database/query/sqlsrv.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Query Building Class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Database
|
||||
* @since 11.1
|
||||
*/
|
||||
class JDatabaseQuerySqlsrv extends JDatabaseQuery
|
||||
{
|
||||
/**
|
||||
* The character(s) used to quote SQL statement names such as table names or field names,
|
||||
* etc. The child classes should define this as necessary. If a single character string the
|
||||
* same character is used for both sides of the quoted name, else the first character will be
|
||||
* used for the opening quote and the second for the closing quote.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $name_quotes = '`';
|
||||
|
||||
/**
|
||||
* The null or zero representation of a timestamp for the database driver. This should be
|
||||
* defined in child classes to hold the appropriate value for the engine.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $null_date = '1900-01-01 00:00:00';
|
||||
|
||||
/**
|
||||
* Magic function to convert the query to a string.
|
||||
*
|
||||
* @return string The completed query.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$query = '';
|
||||
|
||||
switch ($this->type)
|
||||
{
|
||||
case 'insert':
|
||||
$query .= (string) $this->insert;
|
||||
|
||||
// Set method
|
||||
if ($this->set)
|
||||
{
|
||||
$query .= (string) $this->set;
|
||||
}
|
||||
// Columns-Values method
|
||||
elseif ($this->values)
|
||||
{
|
||||
if ($this->columns)
|
||||
{
|
||||
$query .= (string) $this->columns;
|
||||
}
|
||||
|
||||
$elements = $this->insert->getElements();
|
||||
$tableName = array_shift($elements);
|
||||
|
||||
$query .= 'VALUES ';
|
||||
$query .= (string) $this->values;
|
||||
|
||||
if ($this->autoIncrementField)
|
||||
{
|
||||
$query = 'SET IDENTITY_INSERT ' . $tableName . ' ON;' . $query . 'SET IDENTITY_INSERT ' . $tableName . ' OFF;';
|
||||
}
|
||||
|
||||
if ($this->where)
|
||||
{
|
||||
$query .= (string) $this->where;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$query = parent::__toString();
|
||||
break;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a value to a char.
|
||||
*
|
||||
* Ensure that the value is properly quoted before passing to the method.
|
||||
*
|
||||
* @param string $value The value to cast as a char.
|
||||
*
|
||||
* @return string Returns the cast value.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function castAsChar($value)
|
||||
{
|
||||
return 'CAST(' . $value . ' as NVARCHAR(10))';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the function to determine the length of a character string.
|
||||
*
|
||||
* @param string $field A value.
|
||||
* @param string $operator Comparison operator between charLength integer value and $condition
|
||||
* @param string $condition Integer value to compare charLength with.
|
||||
*
|
||||
* @return string The required char length call.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function charLength($field, $operator = null, $condition = null)
|
||||
{
|
||||
return 'DATALENGTH(' . $field . ')' . (isset($operator) && isset($condition) ? ' ' . $operator . ' ' . $condition : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates an array of column names or values.
|
||||
*
|
||||
* @param array $values An array of values to concatenate.
|
||||
* @param string $separator As separator to place between each value.
|
||||
*
|
||||
* @return string The concatenated values.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function concatenate($values, $separator = null)
|
||||
{
|
||||
if ($separator)
|
||||
{
|
||||
return '(' . implode('+' . $this->quote($separator) . '+', $values) . ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '(' . implode('+', $values) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current date and time.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function currentTimestamp()
|
||||
{
|
||||
return 'GETDATE()';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of a string in bytes.
|
||||
*
|
||||
* @param string $value The string to measure.
|
||||
*
|
||||
* @return integer
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function length($value)
|
||||
{
|
||||
return 'LEN(' . $value . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to the current date and time.
|
||||
* Usage:
|
||||
* $query->select($query->dateAdd());
|
||||
* Prefixing the interval with a - (negative sign) will cause subtraction to be used.
|
||||
*
|
||||
* @param datetime $date The date to add to; type may be time or datetime.
|
||||
* @param string $interval The string representation of the appropriate number of units
|
||||
* @param string $datePart The part of the date to perform the addition on
|
||||
*
|
||||
* @return string The string with the appropriate sql for addition of dates
|
||||
*
|
||||
* @since 13.1
|
||||
* @note Not all drivers support all units.
|
||||
* @link http://msdn.microsoft.com/en-us/library/ms186819.aspx for more information
|
||||
*/
|
||||
public function dateAdd($date, $interval, $datePart)
|
||||
{
|
||||
return "DATEADD('" . $datePart . "', '" . $interval . "', '" . $date . "'" . ')';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user