PageRenderTime 32ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/database/query/sqlite.php

https://bitbucket.org/eternaware/joomus
PHP | 182 lines | 70 code | 19 blank | 93 comment | 8 complexity | be5e5f7ca99a02ba17ea68015b66a88b MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Platform
  4 * @subpackage  Database
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE
  8 */
  9
 10defined('JPATH_PLATFORM') or die;
 11
 12/**
 13 * SQLite Query Building Class.
 14 *
 15 * @package     Joomla.Platform
 16 * @subpackage  Database
 17 * @since       12.1
 18 */
 19class JDatabaseQuerySqlite extends JDatabaseQueryPdo implements JDatabaseQueryPreparable, JDatabaseQueryLimitable
 20{
 21	/**
 22	 * @var integer
 23	 * @since 12.1
 24	 */
 25	protected $limit;
 26
 27	/**
 28	 * @var integer
 29	 * @since 12.1
 30	 */
 31	protected $offset;
 32
 33	/**
 34	 * @var mixed
 35	 * @since 12.1
 36	 */
 37	protected $bounded = array();
 38
 39	/**
 40	 * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
 41	 * removes a variable that has been bounded from the internal bounded array when the passed in value is null.
 42	 *
 43	 * @param   string|integer  $key            The key that will be used in your SQL query to reference the value. Usually of
 44	 *                                          the form ':key', but can also be an integer.
 45	 * @param   mixed           &$value         The value that will be bound. The value is passed by reference to support output
 46	 *                                          parameters such as those possible with stored procedures.
 47	 * @param   integer         $dataType       Constant corresponding to a SQL datatype.
 48	 * @param   integer         $length         The length of the variable. Usually required for OUTPUT parameters.
 49	 * @param   array           $driverOptions  Optional driver options to be used.
 50	 *
 51	 * @return  JDatabaseQuery
 52	 *
 53	 * @since   12.1
 54	 */
 55	public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
 56	{
 57		// Case 1: Empty Key (reset $bounded array)
 58		if (empty($key))
 59		{
 60			$this->bounded = array();
 61			return $this;
 62		}
 63
 64		// Case 2: Key Provided, null value (unset key from $bounded array)
 65		if (is_null($value))
 66		{
 67			if (isset($this->bounded[$key]))
 68			{
 69				unset($this->bounded[$key]);
 70			}
 71
 72			return $this;
 73		}
 74
 75		$obj = new stdClass;
 76
 77		$obj->value = &$value;
 78		$obj->dataType = $dataType;
 79		$obj->length = $length;
 80		$obj->driverOptions = $driverOptions;
 81
 82		// Case 3: Simply add the Key/Value into the bounded array
 83		$this->bounded[$key] = $obj;
 84
 85		return $this;
 86	}
 87
 88	/**
 89	 * Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
 90	 * returned.
 91	 *
 92	 * @param   mixed  $key  The bounded variable key to retrieve.
 93	 *
 94	 * @return  mixed
 95	 *
 96	 * @since   12.1
 97	 */
 98	public function &getBounded($key = null)
 99	{
100		if (empty($key))
101		{
102			return $this->bounded;
103		}
104		else
105		{
106			if (isset($this->bounded[$key]))
107			{
108				return $this->bounded[$key];
109			}
110		}
111	}
112
113	/**
114	 * Clear data from the query or a specific clause of the query.
115	 *
116	 * @param   string  $clause  Optionally, the name of the clause to clear, or nothing to clear the whole query.
117	 *
118	 * @return  JDatabaseQuery  Returns this object to allow chaining.
119	 *
120	 * @since   12.1
121	 */
122	public function clear($clause = null)
123	{
124		switch ($clause)
125		{
126			case null:
127				$this->bounded = array();
128				break;
129		}
130
131		parent::clear($clause);
132
133		return $this;
134	}
135
136	/**
137	 * Method to modify a query already in string format with the needed
138	 * additions to make the query limited to a particular number of
139	 * results, or start at a particular offset. This method is used
140	 * automatically by the __toString() method if it detects that the
141	 * query implements the JDatabaseQueryLimitable interface.
142	 *
143	 * @param   string   $query   The query in string format
144	 * @param   integer  $limit   The limit for the result set
145	 * @param   integer  $offset  The offset for the result set
146	 *
147	 * @return  string
148	 *
149	 * @since   12.1
150	 */
151	public function processLimit($query, $limit, $offset = 0)
152	{
153		if ($limit > 0 || $offset > 0)
154		{
155			$query .= ' LIMIT ' . $offset . ', ' . $limit;
156		}
157
158		return $query;
159	}
160
161	/**
162	 * Sets the offset and limit for the result set, if the database driver supports it.
163	 *
164	 * Usage:
165	 * $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
166	 * $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
167	 *
168	 * @param   integer  $limit   The limit for the result set
169	 * @param   integer  $offset  The offset for the result set
170	 *
171	 * @return  JDatabaseQuery  Returns this object to allow chaining.
172	 *
173	 * @since   12.1
174	 */
175	public function setLimit($limit = 0, $offset = 0)
176	{
177		$this->limit = (int) $limit;
178		$this->offset = (int) $offset;
179
180		return $this;
181	}
182}