MediaWiki master
|
Sql abstraction object. More...
Inherits Wikimedia\Rdbms\Platform\ISQLPlatform.
Inherited by Wikimedia\Rdbms\Platform\MySQLPlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Public Member Functions | |||||||||||||||||||
__construct (DbQuoter $quoter, LoggerInterface $logger=null, DatabaseDomain $currentDomain=null, $errorLogger=null) | |||||||||||||||||||
addIdentifierQuotes ( $s) | |||||||||||||||||||
Escape a SQL identifier (e.g.table, column, database) for use in a SQL queryDepending on the database this will either be backticks or "double quotes"
| |||||||||||||||||||
anyChar () | |||||||||||||||||||
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query. | |||||||||||||||||||
anyString () | |||||||||||||||||||
Returns a token for buildLike() that denotes a '' to be used in a LIKE query. | |||||||||||||||||||
assertValidUpsertSetArray (array $set, array $uniqueKey, array $rows) | |||||||||||||||||||
bitAnd ( $fieldLeft, $fieldRight) | |||||||||||||||||||
| |||||||||||||||||||
bitNot ( $field) | |||||||||||||||||||
| |||||||||||||||||||
bitOr ( $fieldLeft, $fieldRight) | |||||||||||||||||||
| |||||||||||||||||||
buildComparison (string $op, array $conds) | |||||||||||||||||||
Build a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g. | |||||||||||||||||||
buildConcat ( $stringList) | |||||||||||||||||||
Build a concatenation list to feed into a SQL query.
| |||||||||||||||||||
buildExcludedValue ( $column) | |||||||||||||||||||
Build a reference to a column value from the conflicting proposed upsert() row. | |||||||||||||||||||
buildGreatest ( $fields, $values) | |||||||||||||||||||
Build a GREATEST function statement comparing columns/values.Integer and float values in $values will not be quotedIf $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
| |||||||||||||||||||
buildGroupConcatField ( $delim, $table, $field, $conds='', $join_conds=[]) | |||||||||||||||||||
Build a GROUP_CONCAT or equivalent statement for a query.This is useful for combining a field for several rows into a single string. NULL values will not appear in the output, duplicated values will appear, and the resulting delimiter-separated values have no defined sort order. Code using the results may need to use the PHP unique() or sort() methods.
| |||||||||||||||||||
buildIntegerCast ( $field) | |||||||||||||||||||
| |||||||||||||||||||
buildLeast ( $fields, $values) | |||||||||||||||||||
Build a LEAST function statement comparing columns/values.Integer and float values in $values will not be quotedIf $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
| |||||||||||||||||||
buildLike ( $param,... $params) | |||||||||||||||||||
LIKE statement wrapper.This takes a variable-length argument list with parts of pattern to match containing either string literals that will be escaped or tokens returned by anyChar() or anyString() . Alternatively, the function could be provided with an array of the aforementioned parameters.Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns a LIKE clause that searches for subpages of 'My page title'. Alternatively: $pattern = [ 'My_page_title/', $dbr->anyString() ]; $query .= $dbr->buildLike( $pattern );
| |||||||||||||||||||
buildSelectSubquery ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |||||||||||||||||||
Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery. | |||||||||||||||||||
buildStringCast ( $field) | |||||||||||||||||||
| |||||||||||||||||||
buildSubstring ( $input, $startPosition, $length=null) | |||||||||||||||||||
conditional ( $cond, $caseTrueExpression, $caseFalseExpression) | |||||||||||||||||||
Returns an SQL expression for a simple conditional.This doesn't need to be overridden unless CASE isn't supported in the RDBMS.
| |||||||||||||||||||
decodeExpiry ( $expiry, $format=TS_MW) | |||||||||||||||||||
Decode an expiry time into a DBMS independent format. | |||||||||||||||||||
deleteJoinSqlText ( $delTable, $joinTable, $delVar, $joinVar, $conds) | |||||||||||||||||||
deleteSqlText ( $table, $conds) | |||||||||||||||||||
dispatchingInsertSqlText ( $table, $rows, $options) | |||||||||||||||||||
dropTableSqlText ( $table) | |||||||||||||||||||
encodeExpiry ( $expiry) | |||||||||||||||||||
Encode an expiry time into the DBMS dependent format. | |||||||||||||||||||
escapeLikeInternal ( $s, $escapeChar='`') | |||||||||||||||||||
extractSingleFieldFromList ( $var) | |||||||||||||||||||
factorConds ( $condsArray) | |||||||||||||||||||
Given an array of condition arrays representing an OR list of AND lists, for example: | |||||||||||||||||||
fieldNameWithAlias ( $name, $alias=false) | |||||||||||||||||||
Get an aliased field name e.g. | |||||||||||||||||||
getInfinity () | |||||||||||||||||||
Find out when 'infinity' is.Most DBMSes support this. This is a special keyword for timestamps in PostgreSQL, and works with CHAR(14) as well because "i" sorts after all numbers.
| |||||||||||||||||||
getQueryVerb ( $sql) | |||||||||||||||||||
getTableAliases () | |||||||||||||||||||
ignoreIndexClause ( $index) | |||||||||||||||||||
IGNORE INDEX clause. | |||||||||||||||||||
implicitOrderby () | |||||||||||||||||||
Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1.
| |||||||||||||||||||
indexName ( $index) | |||||||||||||||||||
Allows for index remapping in queries where this is not consistent across DBMS. | |||||||||||||||||||
insertNonConflictingSqlText ( $table, array $rows) | |||||||||||||||||||
insertSelectNativeSqlText ( $destTable, $srcTable, array $varMap, $conds, $fname, array $insertOptions, array $selectOptions, $selectJoinConds) | |||||||||||||||||||
insertSqlText ( $table, array $rows) | |||||||||||||||||||
isFlagInOptions ( $option, array $options) | |||||||||||||||||||
isQuotedIdentifier ( $name) | |||||||||||||||||||
Returns if the given identifier looks quoted or not according to the database convention for quoting identifiers. | |||||||||||||||||||
isTransactableQuery (Query $sql) | |||||||||||||||||||
Determine whether a SQL statement is sensitive to isolation level. | |||||||||||||||||||
isWriteQuery ( $sql, $flags) | |||||||||||||||||||
Determine whether a query writes to the DB. | |||||||||||||||||||
limitResult ( $sql, $limit, $offset=false) | |||||||||||||||||||
Construct a LIMIT query with optional offset.The SQL should be adjusted so that only the first $limit rows are returned. If $offset is provided as well, then the first $offset rows should be discarded, and the next $limit rows should be returned. If the result of the query is not ordered, then the rows to be returned are theoretically arbitrary.$sql is expected to be a SELECT, if that makes a difference.
| |||||||||||||||||||
lockIsFreeSQLText ( $lockName) | |||||||||||||||||||
lockSQLText ( $lockName, $timeout) | |||||||||||||||||||
makeInsertLists (array $rows, $aliasPrefix='', array $typeByColumn=[]) | |||||||||||||||||||
Make SQL lists of columns, row tuples, and column aliases for INSERT/VALUES expressions. | |||||||||||||||||||
makeKeyCollisionCondition (array $rows, array $uniqueKey) | |||||||||||||||||||
Build an SQL condition to find rows with matching key values to those in $rows. | |||||||||||||||||||
makeList (array $a, $mode=self::LIST_COMMA) | |||||||||||||||||||
Makes an encoded list of strings from an array. | |||||||||||||||||||
makeWhereFrom2d ( $data, $baseKey, $subKey) | |||||||||||||||||||
Build a "OR" condition with pairs from a two-dimensional array. | |||||||||||||||||||
normalizeConditions ( $conds, $fname) | |||||||||||||||||||
normalizeOptions ( $options) | |||||||||||||||||||
normalizeUpsertParams ( $uniqueKeys, &$rows) | |||||||||||||||||||
Validate and normalize parameters to upsert() or replace() | |||||||||||||||||||
qualifiedTableComponents ( $name) | |||||||||||||||||||
Get the table components needed for a query given the currently selected database. | |||||||||||||||||||
releaseSavepointSqlText ( $identifier) | |||||||||||||||||||
replaceVars ( $ins) | |||||||||||||||||||
Database-independent variable replacement. | |||||||||||||||||||
rollbackSqlText () | |||||||||||||||||||
rollbackToSavepointSqlText ( $identifier) | |||||||||||||||||||
savepointSqlText ( $identifier) | |||||||||||||||||||
selectSQLText ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |||||||||||||||||||
Take the same arguments as IDatabase::select() and return the SQL it would use.This can be useful for making UNION queries, where the SQL text of each query is needed. In general, however, callers outside of Database classes should just use select().
| |||||||||||||||||||
setCurrentDomain (DatabaseDomain $currentDomain) | |||||||||||||||||||
setIndexAliases (array $aliases) | |||||||||||||||||||
Convert certain index names to alternative names before querying the DB.Note that this applies to indexes regardless of the table they belong to.This can be employed when an index was renamed X => Y in code, but the new Y-named indexes were not yet built on all DBs. After all the Y-named ones are added by the DBA, the aliases can be removed, and then the old X-named indexes dropped.
| |||||||||||||||||||
setPrefix ( $prefix) | |||||||||||||||||||
setSchemaVars ( $vars) | |||||||||||||||||||
Set schema variables to be used when streaming commands from SQL files or stdin. | |||||||||||||||||||
setTableAliases (array $aliases) | |||||||||||||||||||
Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name.For example, "user" can be converted to "myschema.mydbname.user" for convenience. Appearances like user , somedb.user, somedb.someschema.user will used literally.Calling this twice will completely clear any old table aliases. Also, note that callers are responsible for making sure the schemas and databases actually exist.
| |||||||||||||||||||
strreplace ( $orig, $old, $new) | |||||||||||||||||||
Returns a SQL expression for simple string replacement (e.g.REPLACE() in mysql)
| |||||||||||||||||||
tableName ( $name, $format='quoted') | |||||||||||||||||||
Format a table name ready for use in constructing an SQL query.This does two important things: it quotes the table names to clean them up, and it adds a table prefix if only given a table name with no quotes.All functions of this object which require a table name call this function themselves. Pass the canonical name to such functions. This is only needed when calling query() directly.
| |||||||||||||||||||
tableNames (... $tables) | |||||||||||||||||||
Fetch a number of table names into an associative array. | |||||||||||||||||||
tableNamesN (... $tables) | |||||||||||||||||||
Fetch a number of table names into a zero-indexed numerical array. | |||||||||||||||||||
timestamp ( $ts=0) | |||||||||||||||||||
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
| |||||||||||||||||||
timestampOrNull ( $ts=null) | |||||||||||||||||||
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS. | |||||||||||||||||||
unionQueries ( $sqls, $all, $options=[]) | |||||||||||||||||||
Construct a UNION query.This is used for providing overload point for other DB abstractions not compatible with the MySQL syntax.
| |||||||||||||||||||
unionSupportsOrderAndLimit () | |||||||||||||||||||
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
| |||||||||||||||||||
unlockSQLText ( $lockName) | |||||||||||||||||||
updateSqlText ( $table, $set, $conds, $options) | |||||||||||||||||||
useIndexClause ( $index) | |||||||||||||||||||
USE INDEX clause. | |||||||||||||||||||
![]() | |||||||||||||||||||
buildSubString ( $input, $startPosition, $length=null) | |||||||||||||||||||
Build a SUBSTRING function. | |||||||||||||||||||
Protected Member Functions | |
assertBuildSubstringParams ( $startPosition, $length) | |
Check type and bounds for parameters to self::buildSubstring() | |
assertValidUpsertRowArray (array $rows, array $uniqueKey) | |
buildSuperlative ( $sqlfunc, $fields, $values) | |
Build a superlative function statement comparing columns/values. | |
fieldNamesWithAlias ( $fields) | |
Gets an array of aliased field names. | |
getDefaultSchemaVars () | |
Get schema variables to use if none have been set via setSchemaVars(). | |
getSchemaVars () | |
Get schema variables. | |
makeGroupByWithHaving ( $options) | |
Returns an optional GROUP BY with an optional HAVING. | |
makeInsertNonConflictingVerbAndOptions () | |
makeOrderBy ( $options) | |
Returns an optional ORDER BY. | |
makeSelectOptions (array $options) | |
Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query. | |
makeUpdateOptions ( $options) | |
Make UPDATE options for the Database::update function. | |
makeUpdateOptionsArray ( $options) | |
Make UPDATE options array for Database::makeUpdateOptions. | |
normalizeJoinType (string $joinType) | |
Validate and normalize a join type. | |
normalizeRowArray (array $rowOrRows) | |
relationSchemaQualifier () | |
tableNamesWithIndexClauseOrJOIN ( $tables, $use_index=[], $ignore_index=[], $join_conds=[]) | |
Get the aliased table name clause for a FROM clause which might have a JOIN and/or USE INDEX or IGNORE INDEX clause. | |
tableNameWithAlias ( $table, $alias=false) | |
Get an aliased table name. | |
Protected Attributes | |
DatabaseDomain null | $currentDomain |
callable | $errorLogger |
Error logging callback. | |
string[] | $indexAliases = [] |
Current map of (index alias => index) | |
LoggerInterface | $logger |
DbQuoter | $quoter |
array null | $schemaVars |
Current variables use for schema element placeholders. | |
array[] | $tableAliases = [] |
Current map of (table => (dbname, schema, prefix) map) | |
Additional Inherited Members | |
![]() | |
const | QUERY_PSEUDO_PERMANENT = 2 |
Track a TEMPORARY table CREATE as if it was for a permanent table (for testing) | |
Sql abstraction object.
This class nor any of its subclasses shouldn't create a db connection. It also should not become stateful. The constructor should only rely on addQuotes() method in Database. Later that should be replaced with an implementation that doesn't use db connections.
Definition at line 46 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::__construct | ( | DbQuoter | $quoter, |
LoggerInterface | $logger = null , |
||
DatabaseDomain | $currentDomain = null , |
||
$errorLogger = null |
|||
) |
Definition at line 62 of file SQLPlatform.php.
References Wikimedia\Rdbms\Platform\SQLPlatform\$currentDomain, Wikimedia\Rdbms\Platform\SQLPlatform\$errorLogger, Wikimedia\Rdbms\Platform\SQLPlatform\$logger, and Wikimedia\Rdbms\Platform\SQLPlatform\$quoter.
Wikimedia\Rdbms\Platform\SQLPlatform::addIdentifierQuotes | ( | $s | ) |
Escape a SQL identifier (e.g.table, column, database) for use in a SQL queryDepending on the database this will either be backticks
or "double quotes"
string | $s |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 105 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SQLPlatform\buildSuperlative().
Wikimedia\Rdbms\Platform\SQLPlatform::anyChar | ( | ) |
Returns a token for buildLike()
that denotes a '_' to be used in a LIKE query.
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 447 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::anyString | ( | ) |
Returns a token for buildLike()
that denotes a '' to be used in a LIKE query.
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 451 of file SQLPlatform.php.
|
protected |
Check type and bounds for parameters to self::buildSubstring()
All supported databases have substring functions that behave the same for positive $startPosition and non-negative $length, but behaviors differ when given negative $startPosition or negative $length. The simplest solution to that is to just forbid those values.
int | $startPosition | |
int | null | $length |
Definition at line 572 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SqlitePlatform\buildSubstring().
|
finalprotected |
array<int,array> | $rows Normalized list of rows to insert | |
string[] | $uniqueKey | Columns of the unique key to UPSERT upon |
Definition at line 1846 of file SQLPlatform.php.
|
final |
array | $set | Combined column/literal assignment map and SQL assignment list |
string[] | $uniqueKey | Columns of the unique key to UPSERT upon |
array<int,array> | $rows List of rows to upsert |
Definition at line 1864 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::bitAnd | ( | $fieldLeft, | |
$fieldRight | |||
) |
string | int | $fieldLeft | |
string | int | $fieldRight |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 89 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::bitNot | ( | $field | ) |
string | int | $field |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 81 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::bitOr | ( | $fieldLeft, | |
$fieldRight | |||
) |
string | int | $fieldLeft | |
string | int | $fieldRight |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 97 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildComparison | ( | string | $op, |
array | $conds | ||
) |
Build a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g.
paging through results or doing batch operations.
For example, you might be displaying a list of people ordered alphabetically by their last and first name, split across multiple pages. The first page of the results ended at Jane Doe. When building the query for the next page, you would use:
$queryBuilder->where( $db->buildComparison( '>', [ 'last' => 'Doe', 'first' => 'Jane' ] ) );
This will return people whose last name follows Doe, or whose last name is Doe and first name follows Jane.
Note that the order of keys in the associative array $conds is significant, and must match the order of fields used by the index.
When comparing a single value, prefer using the expression builder:
$db->expr( 'key', '<=', $val ) // equivalent to: $db->buildComparison( '<=', [ 'key' => $val ] ) 'key <= ' . $db->addQuotes( $val )
string | $op | Comparison operator, one of '>', '>=', '<', '<=' |
non-empty-array<string,mixed> | $conds Map of field names to their values to use in the comparison |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 164 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildConcat | ( | $stringList | ) |
Build a concatenation list to feed into a SQL query.
string[] | $stringList | Raw SQL expression list; caller is responsible for escaping |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 396 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildExcludedValue | ( | $column | ) |
Build a reference to a column value from the conflicting proposed upsert() row.
The reference comes in the form of an alias, function, or parenthesized SQL expression. It can be used in upsert() SET expressions to handle the merging of column values between each conflicting pair of existing and proposed rows. Such proposed rows are said to have been "excluded" from insertion in favor of updating the existing row.
This is useful for multi-row upserts() since the proposed values cannot just be included as literals in the SET expressions.
string | $column | Column name |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 1701 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildGreatest | ( | $fields, | |
$values | |||
) |
Build a GREATEST function statement comparing columns/values.Integer and float values in $values will not be quotedIf $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
string | string[] | $fields | Name(s) of column(s) with values to compare |
string | int | float | string[] | int[] | float[] | $values | Values to compare |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 112 of file SQLPlatform.php.
References Wikimedia\Rdbms\Platform\SQLPlatform\buildSuperlative().
Wikimedia\Rdbms\Platform\SQLPlatform::buildGroupConcatField | ( | $delim, | |
$table, | |||
$field, | |||
$conds = '' , |
|||
$join_conds = [] |
|||
) |
Build a GROUP_CONCAT or equivalent statement for a query.This is useful for combining a field for several rows into a single string. NULL values will not appear in the output, duplicated values will appear, and the resulting delimiter-separated values have no defined sort order. Code using the results may need to use the PHP unique() or sort() methods.
string | $delim | Glue to bind the results together |
string | array | $table | Table name |
string | $field | Field name |
string | array | $conds | Conditions |
string | array | $join_conds | Join conditions |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1316 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildIntegerCast | ( | $field | ) |
string | $field | Field or column to cast |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 603 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildLeast | ( | $fields, | |
$values | |||
) |
Build a LEAST function statement comparing columns/values.Integer and float values in $values will not be quotedIf $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
string | string[] | $fields | Name(s) of column(s) with values to compare |
string | int | float | string[] | int[] | float[] | $values | Values to compare |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 119 of file SQLPlatform.php.
References Wikimedia\Rdbms\Platform\SQLPlatform\buildSuperlative().
Wikimedia\Rdbms\Platform\SQLPlatform::buildLike | ( | $param, | |
$params | |||
) |
LIKE statement wrapper.This takes a variable-length argument list with parts of pattern to match containing either string literals that will be escaped or tokens returned by anyChar()
or anyString()
. Alternatively, the function could be provided with an array of the aforementioned parameters.Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns a LIKE clause that searches for subpages of 'My page title'. Alternatively: $pattern = [ 'My_page_title/', $dbr->anyString() ]; $query .= $dbr->buildLike( $pattern );
array[] | string | LikeMatch | $param | |
string|LikeMatch | ...$params |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 435 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildSelectSubquery | ( | $table, | |
$vars, | |||
$conds = '' , |
|||
$fname = __METHOD__ , |
|||
$options = [] , |
|||
$join_conds = [] |
|||
) |
Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery.
string | array | $table | Table name |
string | array | $vars | Field names |
string | array | $conds | Conditions |
string | $fname | Caller function name |
string | array | $options | Query options |
string | array | $join_conds | Join conditions |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 1324 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildStringCast | ( | $field | ) |
string | $field | Field or column to cast |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 593 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::buildSubstring | ( | $input, | |
$startPosition, | |||
$length = null |
|||
) |
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 551 of file SQLPlatform.php.
|
protected |
Build a superlative function statement comparing columns/values.
Integer and float values in $values will not be quoted
If $fields is an array, then each value with a string key is treated as an expression (which must be manually quoted); such string keys do not appear in the SQL and are only descriptive aliases.
string | $sqlfunc | Name of a SQL function |
string | string[] | $fields | Name(s) of column(s) with values to compare |
string | int | float | string[] | int[] | float[] | $values | Values to compare |
Definition at line 137 of file SQLPlatform.php.
References Wikimedia\Rdbms\Platform\SQLPlatform\addIdentifierQuotes().
Referenced by Wikimedia\Rdbms\Platform\SqlitePlatform\buildGreatest(), Wikimedia\Rdbms\Platform\SQLPlatform\buildGreatest(), Wikimedia\Rdbms\Platform\SqlitePlatform\buildLeast(), and Wikimedia\Rdbms\Platform\SQLPlatform\buildLeast().
Wikimedia\Rdbms\Platform\SQLPlatform::conditional | ( | $cond, | |
$caseTrueExpression, | |||
$caseFalseExpression | |||
) |
Returns an SQL expression for a simple conditional.This doesn't need to be overridden unless CASE isn't supported in the RDBMS.
string | array | IExpression | $cond | SQL condition expression (yields a boolean) |
string | $caseTrueExpression | SQL expression to return when the condition is true |
string | $caseFalseExpression | SQL expression to return when the condition is false |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 488 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::decodeExpiry | ( | $expiry, | |
$format = TS_MW |
|||
) |
Decode an expiry time into a DBMS independent format.
string | $expiry | DB timestamp field value for expiry |
int | $format | TS_* constant, defaults to TS_MW |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 539 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::deleteJoinSqlText | ( | $delTable, | |
$joinTable, | |||
$delVar, | |||
$joinVar, | |||
$conds | |||
) |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 1495 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::deleteSqlText | ( | $table, | |
$conds | |||
) |
string | $table | |
string | array | $conds |
Definition at line 1516 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::dispatchingInsertSqlText | ( | $table, | |
$rows, | |||
$options | |||
) |
Definition at line 1723 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::dropTableSqlText | ( | $table | ) |
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1632 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::encodeExpiry | ( | $expiry | ) |
Encode an expiry time into the DBMS dependent format.
string | $expiry | Timestamp for expiry, or the 'infinity' string |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 533 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::escapeLikeInternal | ( | $s, | |
$escapeChar = '`' |
|||
) |
string | $s | |
string | $escapeChar |
Definition at line 423 of file SQLPlatform.php.
|
final |
array | string | $var | Field parameter in the style of select() |
Definition at line 1912 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::factorConds | ( | $condsArray | ) |
Given an array of condition arrays representing an OR list of AND lists, for example:
(A=1 AND B=2) OR (A=1 AND B=3)
produce an SQL expression in which the conditions are factored:
(A=1 AND (B=2 OR B=3))
We also use IN() to simplify further:
(A=1 AND (B IN (2,3))
More compactly, in boolean algebra notation, a sum of products, e.g. AB + AC is factored to produce A(B+C). Factoring proceeds recursively to reduce expressions with any number of variables, for example AEP + AEQ + AFP + AFQ = A(E(P+Q) + F(P+Q))
The algorithm is simple and will not necessarily find the shortest possible expression. For the best results, fields should be given in a consistent order, and the fields with values likely to be shared should be leftmost in the associative arrays.
array | $condsArray | An array of associative arrays. The associative array keys represent field names, and the values represent the field values to compare against. |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 310 of file SQLPlatform.php.
|
protected |
Gets an array of aliased field names.
array | $fields | [ [alias] => field ] |
Definition at line 818 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::fieldNameWithAlias | ( | $name, | |
$alias = false |
|||
) |
Get an aliased field name e.g.
fieldName AS newFieldName
string | $name | Field name |
string | false | $alias | Alias (optional) |
Definition at line 839 of file SQLPlatform.php.
|
protected |
Get schema variables to use if none have been set via setSchemaVars().
Override this in derived classes to provide variables for tables.sql and SQL patch files.
Definition at line 1951 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::getInfinity | ( | ) |
Find out when 'infinity' is.Most DBMSes support this. This is a special keyword for timestamps in PostgreSQL, and works with CHAR(14) as well because "i" sorts after all numbers.
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 529 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::getQueryVerb | ( | $sql | ) |
string | $sql | SQL query |
Definition at line 1643 of file SQLPlatform.php.
References Wikimedia\Rdbms\QueryBuilderFromRawSql\buildQuery().
|
protected |
Get schema variables.
If none have been set via setSchemaVars(), then use some defaults from the current object.
Definition at line 1938 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::getTableAliases | ( | ) |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 646 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::ignoreIndexClause | ( | $index | ) |
IGNORE INDEX clause.
The inverse of Database::useIndexClause.
string | $index |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 1199 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::implicitOrderby | ( | ) |
Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1.
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 611 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::indexName | ( | $index | ) |
Allows for index remapping in queries where this is not consistent across DBMS.
TODO: Make it protected once all the code is moved over.
string | $index |
Definition at line 623 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\MySQLPlatform\ignoreIndexClause(), and Wikimedia\Rdbms\Platform\MySQLPlatform\useIndexClause().
Wikimedia\Rdbms\Platform\SQLPlatform::insertNonConflictingSqlText | ( | $table, | |
array | $rows | ||
) |
Definition at line 1389 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::insertSelectNativeSqlText | ( | $destTable, | |
$srcTable, | |||
array | $varMap, | ||
$conds, | |||
$fname, | |||
array | $insertOptions, | ||
array | $selectOptions, | ||
$selectJoinConds | |||
) |
Definition at line 1409 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::insertSqlText | ( | $table, | |
array | $rows | ||
) |
Definition at line 1333 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::isFlagInOptions | ( | $option, | |
array | $options | ||
) |
string | $option | Query option flag (e.g. "IGNORE" or "FOR UPDATE") |
array | $options | Combination option/value map and boolean option list |
Definition at line 1442 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::isQuotedIdentifier | ( | $name | ) |
Returns if the given identifier looks quoted or not according to the database convention for quoting identifiers.
string | $name |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 1169 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::isTransactableQuery | ( | Query | $sql | ) |
Determine whether a SQL statement is sensitive to isolation level.
A SQL statement is considered transactable if its result could vary depending on the transaction isolation level. Operational commands such as 'SET' and 'SHOW' are not considered to be transactable.
Main purpose: Used by query() to decide whether to begin a transaction before the current query (in DBO_TRX mode, on by default).
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1660 of file SQLPlatform.php.
References Wikimedia\Rdbms\Query\getVerb().
Wikimedia\Rdbms\Platform\SQLPlatform::isWriteQuery | ( | $sql, | |
$flags | |||
) |
Determine whether a query writes to the DB.
When in doubt, this returns true.
Main use cases:
string | $sql | SQL query |
int | $flags | Query flags to query() |
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1697 of file SQLPlatform.php.
References Wikimedia\Rdbms\QueryBuilderFromRawSql\buildQuery().
Wikimedia\Rdbms\Platform\SQLPlatform::limitResult | ( | $sql, | |
$limit, | |||
$offset = false |
|||
) |
Construct a LIMIT query with optional offset.The SQL should be adjusted so that only the first $limit rows are returned. If $offset is provided as well, then the first $offset rows should be discarded, and the next $limit rows should be returned. If the result of the query is not ordered, then the rows to be returned are theoretically arbitrary.$sql is expected to be a SELECT, if that makes a difference.
string | $sql | SQL query we will append the limit too |
int | $limit | The SQL limit |
int | false | $offset | The SQL offset (default false) |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 404 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::lockIsFreeSQLText | ( | $lockName | ) |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform, and Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 2012 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::lockSQLText | ( | $lockName, | |
$timeout | |||
) |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform, and Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 2008 of file SQLPlatform.php.
|
protected |
Returns an optional GROUP BY with an optional HAVING.
array | $options | Associative array of options |
Definition at line 1274 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::makeInsertLists | ( | array | $rows, |
$aliasPrefix = '' , |
|||
array | $typeByColumn = [] |
||
) |
Make SQL lists of columns, row tuples, and column aliases for INSERT/VALUES expressions.
The tuple column order is that of the columns of the first provided row. The provided rows must have exactly the same keys and ordering thereof.
array[] | $rows | Non-empty list of (column => value) maps |
string | $aliasPrefix | Optional prefix to prepend to the magic alias names |
string[] | $typeByColumn | Optional map of (column => data type) |
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 1355 of file SQLPlatform.php.
|
protected |
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1405 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::makeKeyCollisionCondition | ( | array | $rows, |
array | $uniqueKey | ||
) |
Build an SQL condition to find rows with matching key values to those in $rows.
array[] | $rows | Non-empty list of rows |
string[] | $uniqueKey | List of columns that define a single unique index |
Definition at line 1459 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::makeList | ( | array | $a, |
$mode = self::LIST_COMMA |
|||
) |
Makes an encoded list of strings from an array.
These can be used to make conjunctions or disjunctions on SQL condition strings derived from an array ({
Example usage:
This would set $sql to "rev_page = '$id' AND (rev_minor = 1 OR rev_len < 500)"
array | $a | Containing the data |
int | $mode | IDatabase class constant:
|
DBError | If an error occurs, { |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 212 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\MySQLPlatform\deleteJoinSqlText().
|
protected |
Returns an optional ORDER BY.
array | $options | Associative array of options |
Definition at line 1300 of file SQLPlatform.php.
|
protected |
Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.
array | $options | Associative array of options to be turned into an SQL query, valid keys are listed in the function. |
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1214 of file SQLPlatform.php.
|
protected |
Make UPDATE options for the Database::update function.
array | $options | The options passed to Database::update |
Definition at line 1592 of file SQLPlatform.php.
|
protected |
Make UPDATE options array for Database::makeUpdateOptions.
array | $options |
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1605 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::makeWhereFrom2d | ( | $data, | |
$baseKey, | |||
$subKey | |||
) |
Build a "OR" condition with pairs from a two-dimensional array.
The associative array should have integer keys relating to the $baseKey field. The nested array should have string keys for the $subKey field. The inner values are ignored, and are typically boolean true.
Example usage:
array | $data | Nested array, must be non-empty |
string | $baseKey | Field name to match the base-level keys to (eg 'pl_namespace') |
string | $subKey | Field name to match the sub-level keys to (eg 'pl_title') |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 292 of file SQLPlatform.php.
|
final |
array | string | $conds | |
string | $fname |
Definition at line 1788 of file SQLPlatform.php.
|
protected |
Validate and normalize a join type.
Subclasses may override this to add supported join types.
string | $joinType |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 958 of file SQLPlatform.php.
|
final |
string | array | $options |
Definition at line 1622 of file SQLPlatform.php.
|
finalprotected |
array | $rowOrRows | A single (field => value) map or a list of such maps |
Definition at line 1743 of file SQLPlatform.php.
|
final |
Validate and normalize parameters to upsert() or replace()
string | string[] | string[][] | $uniqueKeys | Unique indexes (only one is allowed) |
array[] | &$rows | The row array, which will be replaced with a normalized version. |
Definition at line 1771 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::qualifiedTableComponents | ( | $name | ) |
Get the table components needed for a query given the currently selected database.
string | $name | Table name in the form of db.schema.table, db.table, or table |
Definition at line 1072 of file SQLPlatform.php.
|
protected |
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 1115 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::releaseSavepointSqlText | ( | $identifier | ) |
Definition at line 1711 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::replaceVars | ( | $ins | ) |
Database-independent variable replacement.
Replaces a set of variables in an SQL statement with their contents as given by $this->getSchemaVars().
Supports '{$var}' {$var}
and / $var / (without the spaces) style variables.
{$var}
should be used for identifiers (e.g. table and database names). It is passed through the database's addIdentifierQuotes method which can be overridden if the database uses something other than backticks.string | $ins | SQL statement to replace variables in |
Definition at line 1976 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::rollbackSqlText | ( | ) |
Definition at line 1719 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::rollbackToSavepointSqlText | ( | $identifier | ) |
Definition at line 1715 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::savepointSqlText | ( | $identifier | ) |
Definition at line 1707 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::selectSQLText | ( | $table, | |
$vars, | |||
$conds = '' , |
|||
$fname = __METHOD__ , |
|||
$options = [] , |
|||
$join_conds = [] |
|||
) |
Take the same arguments as IDatabase::select() and return the SQL it would use.This can be useful for making UNION queries, where the SQL text of each query is needed. In general, however, callers outside of Database classes should just use select().
string | array | $table | Table name(s) |
string | array | $vars | Field names |
string | array | $conds | Conditions |
string | $fname | Caller function name |
string | array | $options | Query options |
string | array | $join_conds | Join conditions |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 666 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SqlitePlatform\buildGroupConcatField().
Wikimedia\Rdbms\Platform\SQLPlatform::setCurrentDomain | ( | DatabaseDomain | $currentDomain | ) |
Definition at line 658 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::setIndexAliases | ( | array | $aliases | ) |
Convert certain index names to alternative names before querying the DB.Note that this applies to indexes regardless of the table they belong to.This can be employed when an index was renamed X => Y in code, but the new Y-named indexes were not yet built on all DBs. After all the Y-named ones are added by the DBA, the aliases can be removed, and then the old X-named indexes dropped.
string[] | $aliases |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 639 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::setPrefix | ( | $prefix | ) |
Definition at line 650 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::setSchemaVars | ( | $vars | ) |
Set schema variables to be used when streaming commands from SQL files or stdin.
Variables appear as SQL comments and are substituted by their corresponding values
array | null | $vars | Map of (variable => value) or null to use the defaults |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 1928 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::setTableAliases | ( | array | $aliases | ) |
Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name.For example, "user" can be converted to "myschema.mydbname.user" for convenience. Appearances like user
, somedb.user, somedb.someschema.user will used literally.Calling this twice will completely clear any old table aliases. Also, note that callers are responsible for making sure the schemas and databases actually exist.
array[] | $aliases | Map of (table => (dbname, schema, prefix) map) |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 631 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::strreplace | ( | $orig, | |
$old, | |||
$new | |||
) |
Returns a SQL expression for simple string replacement (e.g.REPLACE() in mysql)
string | $orig | Column to modify |
string | $old | Column to seek |
string | $new | Column to replace with |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 503 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::tableName | ( | $name, | |
$format = 'quoted' |
|||
) |
Format a table name ready for use in constructing an SQL query.This does two important things: it quotes the table names to clean them up, and it adds a table prefix if only given a table name with no quotes.All functions of this object which require a table name call this function themselves. Pass the canonical name to such functions. This is only needed when calling query()
directly.
string | $name | Database table name |
string | $format | One of: quoted - Automatically pass the table name through addIdentifierQuotes() so that it can be used in a query. raw - Do not add identifier quotes to the table name |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 1012 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\MySQLPlatform\deleteJoinSqlText().
Wikimedia\Rdbms\Platform\SQLPlatform::tableNames | ( | $tables | ) |
Fetch a number of table names into an associative array.
Much like tableName()
, this is only needed when calling query()
directly. Prefer calling other methods, or using SelectQueryBuilder
.
Theoretical example (which really does not require raw SQL):
string | ...$tables |
tableName
or use tableNamesN
instead of calling this function. Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 1139 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::tableNamesN | ( | $tables | ) |
Fetch a number of table names into a zero-indexed numerical array.
Much like tableName()
, this is only needed when calling query()
directly. It is slightly more convenient than tableNames()
, but you should still prefer calling other methods, or using SelectQueryBuilder
.
Theoretical example (which really does not require raw SQL):
string | ...$tables |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 1149 of file SQLPlatform.php.
|
protected |
Get the aliased table name clause for a FROM clause which might have a JOIN and/or USE INDEX or IGNORE INDEX clause.
array | $tables | ( [alias] => table ) |
array | $use_index | Same as for select() |
array | $ignore_index | Same as for select() |
array | $join_conds | Same as for select() |
Definition at line 857 of file SQLPlatform.php.
|
protected |
Get an aliased table name.
This returns strings like "tableName AS newTableName" for aliased tables and "(SELECT * from tableA) newTablename" for subqueries (e.g. derived tables)
string | Subquery | $table | Table name or object with a 'sql' field |
string | false | $alias | Table alias (optional) |
Definition at line 988 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::timestamp | ( | $ts = 0 | ) |
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp
to the format used for inserting into timestamp fields in this DBMS.The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
string | int | $ts |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 511 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::timestampOrNull | ( | $ts = null | ) |
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.
If NULL is input, it is passed through, allowing NULL values to be inserted into timestamp fields.
The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
string | int | null | $ts |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Definition at line 517 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::unionQueries | ( | $sqls, | |
$all, | |||
$options = [] |
|||
) |
Construct a UNION query.This is used for providing overload point for other DB abstractions not compatible with the MySQL syntax.
array | $sqls | SQL statements to combine |
bool | $all | Either IDatabase::UNION_ALL or IDatabase::UNION_DISTINCT |
array | $options | Query options |
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 467 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::unionSupportsOrderAndLimit | ( | ) |
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
Implements Wikimedia\Rdbms\Platform\ISQLPlatform.
Reimplemented in Wikimedia\Rdbms\Platform\SqlitePlatform.
Definition at line 459 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::unlockSQLText | ( | $lockName | ) |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform, and Wikimedia\Rdbms\Platform\PostgresPlatform.
Definition at line 2016 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::updateSqlText | ( | $table, | |
$set, | |||
$conds, | |||
$options | |||
) |
Definition at line 1558 of file SQLPlatform.php.
Wikimedia\Rdbms\Platform\SQLPlatform::useIndexClause | ( | $index | ) |
USE INDEX clause.
This can be used as optimisation in queries that affect tables with multiple indexes if the database does not pick the most optimal one by default. The "right" index might vary between database backends and versions thereof, as such in practice this is biased toward specifically improving performance of large wiki farms that use MySQL or MariaDB (like Wikipedia).
string | $index |
Reimplemented in Wikimedia\Rdbms\Platform\MySQLPlatform.
Definition at line 1186 of file SQLPlatform.php.
|
protected |
Definition at line 52 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SQLPlatform\__construct().
|
protected |
Error logging callback.
Definition at line 60 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SQLPlatform\__construct().
|
protected |
Current map of (index alias => index)
Definition at line 50 of file SQLPlatform.php.
|
protected |
Definition at line 58 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SQLPlatform\__construct().
|
protected |
Definition at line 56 of file SQLPlatform.php.
Referenced by Wikimedia\Rdbms\Platform\SQLPlatform\__construct().
|
protected |
Current variables use for schema element placeholders.
Definition at line 54 of file SQLPlatform.php.
|
protected |
Current map of (table => (dbname, schema, prefix) map)
Definition at line 48 of file SQLPlatform.php.