MediaWiki master
Wikimedia\Rdbms\Platform\MySQLPlatform Class Reference

Inherits Wikimedia\Rdbms\Platform\SQLPlatform.

Inherited by Wikimedia\Rdbms\MWMySQLPlatform.

Collaboration diagram for Wikimedia\Rdbms\Platform\MySQLPlatform:

Public Member Functions

 buildExcludedValue ( $column)
 Build a reference to a column value from the conflicting proposed upsert() row.
 
 buildIntegerCast ( $field)
 
 buildStringCast ( $field)
 
 deleteJoinSqlText ( $delTable, $joinTable, $delVar, $joinVar, $conds)
 
 ignoreIndexClause ( $index)
 
 isTransactableQuery (Query $sql)
 Determine whether a SQL statement is sensitive to isolation level.
 
 lockIsFreeSQLText ( $lockName)
 
 lockSQLText ( $lockName, $timeout)
 
 makeLockName ( $lockName)
 
 unlockSQLText ( $lockName)
 
 useIndexClause ( $index)
 
- Public Member Functions inherited from Wikimedia\Rdbms\Platform\SQLPlatform
 __construct (DbQuoter $quoter, LoggerInterface $logger=null, DatabaseDomain $currentDomain=null, $errorLogger=null)
 
 addIdentifierQuotes ( $s)
 Escape a SQL identifier (e.g.
 
 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.
Parameters
string[]$stringListRaw SQL expression list; caller is responsible for escaping
Returns
string

 
 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.
Parameters
string | string[]$fieldsName(s) of column(s) with values to compare
string | int | float | string[] | int[] | float[]$valuesValues to compare
Returns
mixed
Since
1.35 in IDatabase, moved to ISQLPlatform in 1.39

 
 buildGroupConcatField ( $delim, $table, $field, $conds='', $join_conds=[])
 Build a GROUP_CONCAT or equivalent statement for a query.
 
 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.
Parameters
string | string[]$fieldsName(s) of column(s) with values to compare
string | int | float | string[] | int[] | float[]$valuesValues to compare
Returns
mixed
Since
1.35 in IDatabase, moved to ISQLPlatform in 1.39

 
 buildLike ( $param,... $params)
 LIKE statement wrapper.
 
 buildSelectSubquery ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery.
 
 buildSubstring ( $input, $startPosition, $length=null)
 
 conditional ( $cond, $caseTrueExpression, $caseFalseExpression)
 Returns an SQL expression for a simple conditional.
 
 decodeExpiry ( $expiry, $format=TS_MW)
 Decode an expiry time into a DBMS independent format.
 
 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)
 
 extractTableNameComponents (string $name)
 Extract the dot-separated components of a table name, preserving identifier quotation.
 
 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.
 
 getQueryVerb ( $sql)
 
 getTableAliases ()
 
 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.
 
 limitResult ( $sql, $limit, $offset=false)
 Construct a LIMIT query with optional offset.
 
 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/schema.
 
 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.
 
 setCurrentDomain (DatabaseDomain $currentDomain)
 
 setIndexAliases (array $aliases)
 Convert certain index names to alternative names before querying the DB.
 
 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.
 
 strreplace ( $orig, $old, $new)
 Returns a SQL expression for simple string replacement (e.g.
 
 tableName (string $name, $format='quoted')
 Format a table name ready for use in constructing an SQL query.
 
 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.
 
 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.
 
 unionSupportsOrderAndLimit ()
 Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
Returns
bool

 
 updateSqlText ( $table, $set, $conds, $options)
 
- Public Member Functions inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
 buildSubString ( $input, $startPosition, $length=null)
 Build a SUBSTRING function.
 

Protected Member Functions

 getIdentifierQuoteChar ()
 Get the character used for identifier quoting.
 
 normalizeJoinType (string $joinType)
 Validate and normalize a join type.
 
- Protected Member Functions inherited from Wikimedia\Rdbms\Platform\SQLPlatform
 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.
 
 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.
 

Additional Inherited Members

- Public Attributes inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
const QUERY_PSEUDO_PERMANENT = 2
 Track a TEMPORARY table CREATE as if it was for a permanent table (for testing)
 
- Protected Attributes inherited from Wikimedia\Rdbms\Platform\SQLPlatform
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)
 

Detailed Description

Since
1.39
See also
ISQLPlatform

Definition at line 29 of file MySQLPlatform.php.

Member Function Documentation

◆ buildExcludedValue()

Wikimedia\Rdbms\Platform\MySQLPlatform::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.

See also
IDatabase::upsert()
Parameters
string$columnColumn name
Returns
string SQL expression returning a scalar
Since
1.39

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 95 of file MySQLPlatform.php.

◆ buildIntegerCast()

Wikimedia\Rdbms\Platform\MySQLPlatform::buildIntegerCast ( $field)
Parameters
string$fieldField or column to cast
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 42 of file MySQLPlatform.php.

◆ buildStringCast()

Wikimedia\Rdbms\Platform\MySQLPlatform::buildStringCast ( $field)
Parameters
string$fieldField or column to cast
Returns
string
Since
1.28 in IDatabase, moved to ISQLPlatform in 1.39

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 34 of file MySQLPlatform.php.

◆ deleteJoinSqlText()

Wikimedia\Rdbms\Platform\MySQLPlatform::deleteJoinSqlText ( $delTable,
$joinTable,
$delVar,
$joinVar,
$conds )

◆ getIdentifierQuoteChar()

Wikimedia\Rdbms\Platform\MySQLPlatform::getIdentifierQuoteChar ( )
protected

Get the character used for identifier quoting.

Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 30 of file MySQLPlatform.php.

◆ ignoreIndexClause()

Wikimedia\Rdbms\Platform\MySQLPlatform::ignoreIndexClause ( $index)
Parameters
string$index
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 69 of file MySQLPlatform.php.

References Wikimedia\Rdbms\Platform\SQLPlatform\indexName().

◆ isTransactableQuery()

Wikimedia\Rdbms\Platform\MySQLPlatform::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).

Returns
bool

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 89 of file MySQLPlatform.php.

References Wikimedia\Rdbms\Query\getSQL().

◆ lockIsFreeSQLText()

Wikimedia\Rdbms\Platform\MySQLPlatform::lockIsFreeSQLText ( $lockName)

◆ lockSQLText()

Wikimedia\Rdbms\Platform\MySQLPlatform::lockSQLText ( $lockName,
$timeout )

◆ makeLockName()

◆ normalizeJoinType()

Wikimedia\Rdbms\Platform\MySQLPlatform::normalizeJoinType ( string $joinType)
protected

Validate and normalize a join type.

Subclasses may override this to add supported join types.

Parameters
string$joinType
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 46 of file MySQLPlatform.php.

◆ unlockSQLText()

Wikimedia\Rdbms\Platform\MySQLPlatform::unlockSQLText ( $lockName)

◆ useIndexClause()

Wikimedia\Rdbms\Platform\MySQLPlatform::useIndexClause ( $index)
Parameters
string$index
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 61 of file MySQLPlatform.php.

References Wikimedia\Rdbms\Platform\SQLPlatform\indexName().


The documentation for this class was generated from the following file: