File manager - Edit - /home/opticamezl/www/newok/Query.zip
Back
PK Ҩ�\�36w2: 2: PostgresqlQueryBuilder.phpnu �[��� <?php /** * Part of the Joomla Framework Database Package * * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\Database\Query; /** * Trait for PostgreSQL Query Building. * * @since 2.0.0 */ trait PostgresqlQueryBuilder { /** * The FOR UPDATE element used in "FOR UPDATE" lock * * @var QueryElement * @since 2.0.0 */ protected $forUpdate; /** * The FOR SHARE element used in "FOR SHARE" lock * * @var QueryElement * @since 2.0.0 */ protected $forShare; /** * The NOWAIT element used in "FOR SHARE" and "FOR UPDATE" lock * * @var QueryElement * @since 2.0.0 */ protected $noWait; /** * The LIMIT element * * @var QueryElement * @since 2.0.0 */ protected $limit; /** * The OFFSET element * * @var QueryElement * @since 2.0.0 */ protected $offset; /** * The RETURNING element of INSERT INTO * * @var QueryElement * @since 2.0.0 */ protected $returning; /** * Magic function to convert the query to a string, only for PostgreSQL specific queries * * @return string The completed query. * * @since 2.0.0 */ 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->selectRowNumber) { if ($this->order) { $query .= (string) $this->order; } break; } if ($this->group) { $query .= (string) $this->group; } if ($this->having) { $query .= (string) $this->having; } if ($this->merge) { // Special case for merge foreach ($this->merge as $element) { $query .= (string) $element; } } if ($this->order) { $query .= (string) $this->order; } if ($this->forUpdate) { $query .= (string) $this->forUpdate; } else { if ($this->forShare) { $query .= (string) $this->forShare; } } if ($this->noWait) { $query .= (string) $this->noWait; } $query = $this->processLimit($query, $this->limit, $this->offset); break; case 'update': $query .= (string) $this->update; $query .= (string) $this->set; if ($this->join) { $tmpFrom = $this->from; $tmpWhere = $this->where ? clone $this->where : null; $this->from = null; // Workaround for special case of JOIN with UPDATE foreach ($this->join as $join) { $joinElem = $join->getElements(); $this->from($joinElem[0]); if (isset($joinElem[1])) { $this->where($joinElem[1]); } } $query .= (string) $this->from; if ($this->where) { $query .= (string) $this->where; } $this->from = $tmpFrom; $this->where = $tmpWhere; } elseif ($this->where) { $query .= (string) $this->where; } $query = $this->processLimit($query, $this->limit, $this->offset); 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; } } $query = $this->processLimit($query, $this->limit, $this->offset); break; default: $query = parent::__toString(); break; } if ($this->type === 'select' && $this->alias !== null) { $query = '(' . $query . ') AS ' . $this->alias; } 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 $this * * @since 2.0.0 */ 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 'querySet': case 'from': case 'join': case 'set': case 'where': case 'group': case 'having': case 'merge': case 'order': case 'columns': case 'values': parent::clear($clause); break; default: $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->castAs('CHAR', 'a')); * * @param string $type The type of string to cast as. * @param string $value The value to cast as a char. * @param string $length The value to cast as a char. * * @return string SQL statement to cast the value as a char type. * * @since 1.0 */ public function castAs(string $type, string $value, ?string $length = null) { switch (strtoupper($type)) { case 'CHAR': if (!$length) { return $value . '::text'; } else { return 'CAST(' . $value . ' AS CHAR(' . $length . '))'; } case 'INT': return 'CAST(' . $value . ' AS INTEGER)'; } return parent::castAs($type, $value, $length); } /** * Concatenates an array of column names or values. * * Usage: * $query->select($query->concatenate(array('a', 'b'))); * * @param string[] $values An array of values to concatenate. * @param string|null $separator As separator to place between each value. * * @return string The concatenated values. * * @since 2.0.0 */ public function concatenate($values, $separator = null) { if ($separator !== null) { return implode(' || ' . $this->quote($separator) . ' || ', $values); } return implode(' || ', $values); } /** * Gets the current date and time. * * @return string Return string used in query to obtain * * @since 2.0.0 */ public function currentTimestamp() { return 'NOW()'; } /** * Sets the FOR UPDATE lock on select's output row * * @param string $tableName The table to lock * @param string $glue The glue by which to join the conditions. Defaults to ',' . * * @return $this * * @since 2.0.0 */ public function forUpdate($tableName, $glue = ',') { $this->type = 'forUpdate'; if ($this->forUpdate === null) { $glue = strtoupper($glue); $this->forUpdate = new QueryElement('FOR UPDATE', 'OF ' . $tableName, "$glue "); } else { $this->forUpdate->append($tableName); } return $this; } /** * Sets the FOR SHARE lock on select's output row * * @param string $tableName The table to lock * @param string $glue The glue by which to join the conditions. Defaults to ',' . * * @return $this * * @since 2.0.0 */ public function forShare($tableName, $glue = ',') { $this->type = 'forShare'; if ($this->forShare === null) { $glue = strtoupper($glue); $this->forShare = new QueryElement('FOR SHARE', 'OF ' . $tableName, "$glue "); } else { $this->forShare->append($tableName); } return $this; } /** * Aggregate function to get input values concatenated into a string, separated by delimiter * * Usage: * $query->groupConcat('id', ','); * * @param string $expression The expression to apply concatenation to, this may be a column name or complex SQL statement. * @param string $separator The delimiter of each concatenated value * * @return string Input values concatenated into a string, separated by delimiter * * @since 2.0.0 */ public function groupConcat($expression, $separator = ',') { return 'string_agg(' . $expression . ', ' . $this->quote($separator) . ')'; } /** * 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 2.0.0 */ 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 2.0.0 */ 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 2.0.0 */ 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 2.0.0 */ 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 2.0.0 */ 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 2.0.0 */ public function second($date) { return 'EXTRACT (SECOND FROM ' . $date . ')'; } /** * Sets the NOWAIT lock on select's output row * * @return $this * * @since 2.0.0 */ public function noWait() { $this->type = 'noWait'; if ($this->noWait === null) { $this->noWait = new QueryElement('NOWAIT', null); } return $this; } /** * Set the LIMIT clause to the query * * @param integer $limit Number of rows to return * * @return $this * * @since 2.0.0 */ public function limit($limit = 0) { if ($this->limit === null) { $this->limit = new QueryElement('LIMIT', (int) $limit); } return $this; } /** * Set the OFFSET clause to the query * * @param integer $offset An integer for skipping rows * * @return $this * * @since 2.0.0 */ public function offset($offset = 0) { if ($this->offset === null) { $this->offset = new QueryElement('OFFSET', (int) $offset); } return $this; } /** * Add the RETURNING element to INSERT INTO statement. * * @param mixed $pkCol The name of the primary key column. * * @return $this * * @since 2.0.0 */ public function returning($pkCol) { if ($this->returning === null) { $this->returning = new QueryElement('RETURNING', $pkCol); } 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 2.0.0 */ 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. * * Usage: * $query->select($query->dateAdd()); * * Prefixing the interval with a - (negative sign) will cause subtraction to be used. * * @param string $date The db quoted string representation of 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 2.0.0 * @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 . "'"; } return 'timestamp ' . $date . " - interval '" . ltrim($interval, '-') . ' ' . $datePart . "'"; } /** * Get the regular expression operator * * Usage: * $query->where('field ' . $query->regexp($search)); * * @param string $value The regex pattern. * * @return string * * @since 2.0.0 */ public function regexp($value) { return ' ~* ' . $value; } /** * Get the function to return a random floating-point value * * Usage: * $query->rand(); * * @return string * * @since 2.0.0 */ public function rand() { return ' RANDOM() '; } /** * Find a value in a varchar used like a set. * * Ensure that the value is an integer before passing to the method. * * Usage: * $query->findInSet((int) $parent->id, 'a.assigned_cat_ids') * * @param string $value The value to search for. * @param string $set The set of values. * * @return string A representation of the MySQL find_in_set() function for the driver. * * @since 2.0.0 */ public function findInSet($value, $set) { return " $value = ANY (string_to_array($set, ',')::integer[]) "; } } PK Ҩ�\�� MysqlQueryBuilder.phpnu �[��� <?php /** * Part of the Joomla Framework Database Package * * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\Database\Query; /** * Trait for MySQL Query Building. * * @since 2.0.0 */ trait MysqlQueryBuilder { /** * Magic function to convert the query to a string. * * @return string The completed query. * * @since 2.0.0 */ public function __toString() { switch ($this->type) { case 'select': if ($this->selectRowNumber) { $orderBy = $this->selectRowNumber['orderBy']; $tmpOffset = $this->offset; $tmpLimit = $this->limit; $this->offset = 0; $this->limit = 0; $tmpOrder = $this->order; $this->order = null; $query = parent::__toString(); $this->order = $tmpOrder; $this->offset = $tmpOffset; $this->limit = $tmpLimit; // Add support for second order by, offset and limit $query = PHP_EOL . 'SELECT * FROM (' . $query . PHP_EOL . "ORDER BY $orderBy" . PHP_EOL . ') w'; if ($this->order) { $query .= (string) $this->order; } return $this->processLimit($query, $this->limit, $this->offset); } } return parent::__toString(); } /** * 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 2.0.0 */ public function processLimit($query, $limit, $offset = 0) { if ($limit > 0 && $offset > 0) { $query .= ' LIMIT ' . $offset . ', ' . $limit; } elseif ($limit > 0) { $query .= ' LIMIT ' . $limit; } return $query; } /** * Concatenates an array of column names or values. * * @param string[] $values An array of values to concatenate. * @param string|null $separator As separator to place between each value. * * @return string The concatenated values. * * @since 2.0.0 */ public function concatenate($values, $separator = null) { if ($separator !== null) { $statement = 'CONCAT_WS(' . $this->quote($separator); foreach ($values as $value) { $statement .= ', ' . $value; } return $statement . ')'; } return 'CONCAT(' . implode(',', $values) . ')'; } /** * Aggregate function to get input values concatenated into a string, separated by delimiter * * Usage: * $query->groupConcat('id', ','); * * @param string $expression The expression to apply concatenation to, this may be a column name or complex SQL statement. * @param string $separator The delimiter of each concatenated value * * @return string Input values concatenated into a string, separated by delimiter * * @since 2.0.0 */ public function groupConcat($expression, $separator = ',') { return 'GROUP_CONCAT(' . $expression . ' SEPARATOR ' . $this->quote($separator) . ')'; } /** * Method to quote and optionally escape a string to database requirements for insertion into the database. * * This method is provided for use where the query object is passed to a function for modification. * If you have direct access to the database object, it is recommended you use the quote method directly. * * Note that 'q' is an alias for this method as it is in DatabaseDriver. * * Usage: * $query->quote('fulltext'); * $query->q('fulltext'); * $query->q(array('option', 'fulltext')); * * @param array|string $text A string or an array of strings to quote. * @param boolean $escape True (default) to escape the string, false to leave it unchanged. * * @return string The quoted input string. * * @since 2.0.0 * @throws \RuntimeException if the internal db property is not a valid object. */ abstract public function quote($text, $escape = true); /** * Get the regular expression operator * * Usage: * $query->where('field ' . $query->regexp($search)); * * @param string $value The regex pattern. * * @return string * * @since 2.0.0 */ public function regexp($value) { return ' REGEXP ' . $value; } /** * Get the function to return a random floating-point value * * Usage: * $query->rand(); * * @return string * * @since 2.0.0 */ public function rand() { return ' RAND() '; } /** * Find a value in a varchar used like a set. * * Ensure that the value is an integer before passing to the method. * * Usage: * $query->findInSet((int) $parent->id, 'a.assigned_cat_ids') * * @param string $value The value to search for. * @param string $set The set of values. * * @return string A representation of the MySQL find_in_set() function for the driver. * * @since 2.0.0 */ public function findInSet($value, $set) { return ' find_in_set(' . $value . ', ' . $set . ')'; } /** * Return the number of the current row. * * Usage: * $query->select('id'); * $query->selectRowNumber('ordering,publish_up DESC', 'new_ordering'); * $query->from('#__content'); * * @param string $orderBy An expression of ordering for window function. * @param string $orderColumnAlias An alias for new ordering column. * * @return $this * * @since 2.0.0 * @throws \RuntimeException */ public function selectRowNumber($orderBy, $orderColumnAlias) { $this->validateRowNumber($orderBy, $orderColumnAlias); return $this->select("(SELECT @rownum := @rownum + 1 FROM (SELECT @rownum := 0) AS r) AS $orderColumnAlias"); } /** * Casts a value to a char. * * Ensure that the value is properly quoted before passing to the method. * * Usage: * $query->select($query->castAs('CHAR', 'a')); * * @param string $type The type of string to cast as. * @param string $value The value to cast as a char. * @param string $length The value to cast as a char. * * @return string SQL statement to cast the value as a char type. * * @since 1.0 */ public function castAs(string $type, string $value, ?string $length = null) { switch (strtoupper($type)) { case 'CHAR': if (!$length) { return $value; } else { return 'CAST(' . $value . ' AS CHAR(' . $length . '))'; } case 'INT': return '(' . $value . ' + 0)'; } return parent::castAs($type, $value, $length); } } PK Ҩ�\\���s s PreparableInterface.phpnu �[��� <?php /** * Part of the Joomla Framework Database Package * * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\Database\Query; use Joomla\Database\ParameterType; use Joomla\Database\QueryInterface; trigger_deprecation( 'joomla/database', '2.0.0', '%s() is deprecated and will be removed in 3.0, all query objects should implement %s instead.', PreparableInterface::class, QueryInterface::class ); /** * 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. * * @since 1.0 * @deprecated 3.0 Capabilities will be required in Joomla\Database\QueryInterface */ interface PreparableInterface { /** * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. * * @param array|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. It can be an array, in this case it has to be * same length of $key; The value is passed by reference to support output * parameters such as those possible with stored procedures. * @param array|string $dataType Constant corresponding to a SQL datatype. It can be an array, in this case it * has to be same length of $key * @param integer $length The length of the variable. Usually required for OUTPUT parameters. * @param array $driverOptions Optional driver options to be used. * * @return $this * * @since 1.0 */ public function bind($key, &$value, $dataType = ParameterType::STRING, $length = 0, $driverOptions = []); /** * Method to unbind a bound variable. * * @param array|string|integer $key The key or array of keys to unbind. * * @return $this * * @since 2.0.0 */ public function unbind($key); /** * 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 1.0 */ public function &getBounded($key = null); } PK Ҩ�\Z��� � QueryElement.phpnu �[��� <?php /** * Part of the Joomla Framework Database Package * * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\Database\Query; /** * Query Element Class. * * @since 1.0 */ class QueryElement { /** * The name of the element. * * @var string * @since 1.0 */ protected $name; /** * An array of elements. * * @var string[] * @since 1.0 */ protected $elements = []; /** * Glue piece. * * @var string * @since 1.0 */ protected $glue; /** * Constructor. * * @param string $name The name of the element. * @param string[]|string $elements String or array. * @param string $glue The glue for elements. * * @since 1.0 */ public function __construct($name, $elements, $glue = ',') { $this->name = $name; $this->glue = $glue; $this->append($elements); } /** * Magic function to convert the query element to a string. * * @return string * * @since 1.0 */ public function __toString() { if (substr($this->name, -2) === '()') { return \PHP_EOL . substr($this->name, 0, -2) . '(' . implode($this->glue, $this->elements) . ')'; } return \PHP_EOL . $this->name . ' ' . implode($this->glue, $this->elements); } /** * Appends element parts to the internal list. * * @param string[]|string $elements String or array. * * @return void * * @since 1.0 */ public function append($elements) { if (\is_array($elements)) { $this->elements = array_merge($this->elements, $elements); } else { $this->elements = array_merge($this->elements, [$elements]); } } /** * Gets the elements of this element. * * @return string[] * * @since 1.0 */ public function getElements() { return $this->elements; } /** * Gets the glue of this element. * * @return string Glue of the element. * * @since 2.0.0 */ public function getGlue() { return $this->glue; } /** * Gets the name of this element. * * @return string Name of the element. * * @since 1.7.0 */ public function getName() { return $this->name; } /** * Sets the name of this element. * * @param string $name Name of the element. * * @return $this * * @since 1.3.0 */ public function setName($name) { $this->name = $name; return $this; } /** * Method to provide basic copy support. * * Any object pushed into the data of this class should have its own __clone() implementation. * This method does not support copying objects in a multidimensional array. * * @return void * * @since 1.0 */ public function __clone() { foreach ($this as $k => $v) { if (\is_object($v)) { $this->{$k} = clone $v; } elseif (\is_array($v)) { foreach ($v as $i => $element) { if (\is_object($element)) { $this->{$k}[$i] = clone $element; } } } } } } PK Ҩ�\��>"y y LimitableInterface.phpnu �[��� <?php /** * Part of the Joomla Framework Database Package * * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\Database\Query; use Joomla\Database\QueryInterface; trigger_deprecation( 'joomla/database', '2.0.0', '%s() is deprecated and will be removed in 3.0, all query objects should implement %s instead.', LimitableInterface::class, QueryInterface::class ); /** * Joomla Database Query LimitableInterface. * * @since 1.0 * @deprecated 3.0 Capabilities will be required in Joomla\Database\QueryInterface */ interface LimitableInterface { /** * 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 1.0 */ 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 $this * * @since 1.0 */ public function setLimit($limit = 0, $offset = 0); } PK Ҩ�\�36w2: 2: PostgresqlQueryBuilder.phpnu �[��� PK Ҩ�\�� |: MysqlQueryBuilder.phpnu �[��� PK Ҩ�\\���s s �T PreparableInterface.phpnu �[��� PK Ҩ�\Z��� � �_ QueryElement.phpnu �[��� PK Ҩ�\��>"y y �k LimitableInterface.phpnu �[��� PK � �r
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings