MediaWiki  master
Wikimedia\Rdbms\Platform\ISQLPlatform Interface Reference

Interface for query language. More...

Inheritance diagram for Wikimedia\Rdbms\Platform\ISQLPlatform:

Public Member Functions

 addIdentifierQuotes ( $s)
 Escape a SQL identifier (e.g. More...
 
 anyChar ()
 Returns a token for buildLike() that denotes a '_' to be used in a LIKE query. More...
 
 anyString ()
 Returns a token for buildLike() that denotes a '' to be used in a LIKE query. More...
 
 bitAnd ( $fieldLeft, $fieldRight)
 
 bitNot ( $field)
 
 bitOr ( $fieldLeft, $fieldRight)
 
 buildConcat ( $stringList)
 Build a concatenation list to feed into a SQL query. More...
 
 buildGreatest ( $fields, $values)
 Build a GREATEST function statement comparing columns/values. More...
 
 buildGroupConcatField ( $delim, $table, $field, $conds='', $join_conds=[])
 Build a GROUP_CONCAT or equivalent statement for a query. More...
 
 buildIntegerCast ( $field)
 
 buildLeast ( $fields, $values)
 Build a LEAST function statement comparing columns/values. More...
 
 buildLike ( $param,... $params)
 LIKE statement wrapper. More...
 
 buildSelectSubquery ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery. More...
 
 buildStringCast ( $field)
 
 buildSubString ( $input, $startPosition, $length=null)
 Build a SUBSTRING function. More...
 
 conditional ( $cond, $caseTrueExpression, $caseFalseExpression)
 Returns an SQL expression for a simple conditional. More...
 
 decodeExpiry ( $expiry, $format=TS_MW)
 Decode an expiry time into a DBMS independent format. More...
 
 encodeExpiry ( $expiry)
 Encode an expiry time into the DBMS dependent format. More...
 
 factorConds ( $condsArray)
 Given an array of condition arrays representing an OR list of AND lists, for example: More...
 
 getInfinity ()
 Find out when 'infinity' is. More...
 
 getTableAliases ()
 Return current table aliases. More...
 
 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. More...
 
 limitResult ( $sql, $limit, $offset=false)
 Construct a LIMIT query with optional offset. More...
 
 makeList (array $a, $mode=self::LIST_COMMA)
 Makes an encoded list of strings from an array. More...
 
 makeWhereFrom2d ( $data, $baseKey, $subKey)
 Build a partial where clause from a 2-d array such as used for LinkBatch. More...
 
 selectSQLText ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Take the same arguments as IDatabase::select() and return the SQL it would use. More...
 
 setIndexAliases (array $aliases)
 Convert certain index names to alternative names before querying the DB. More...
 
 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. More...
 
 strreplace ( $orig, $old, $new)
 Returns a SQL expression for simple string replacement (e.g. More...
 
 tableName ( $name, $format='quoted')
 Format a table name ready for use in constructing an SQL query. More...
 
 tableNames (... $tables)
 Fetch a number of table names into an array This is handy when you need to construct SQL for joins. More...
 
 tableNamesN (... $tables)
 Fetch a number of table names into an zero-indexed numerical array This is handy when you need to construct SQL for joins. More...
 
 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. More...
 
 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. More...
 
 unionConditionPermutations ( $table, $vars, array $permute_conds, $extra_conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Construct a UNION query for permutations of conditions. More...
 
 unionQueries ( $sqls, $all)
 Construct a UNION query. More...
 
 unionSupportsOrderAndLimit ()
 Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION. More...
 

Detailed Description

Interface for query language.

Note: This is for simple SQL operations, use QueryBuilder for building full queries.

Methods of this interface should be only used by rdbms library.

Since
1.39

Definition at line 33 of file ISQLPlatform.php.

Member Function Documentation

◆ addIdentifierQuotes()

Wikimedia\Rdbms\Platform\ISQLPlatform::addIdentifierQuotes (   $s)

Escape a SQL identifier (e.g.

table, column, database) for use in a SQL query

Depending on the database this will either be backticks or "double quotes"

Parameters
string$s
Returns
string
Since
1.33

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\MySQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by SiteStatsUpdate\doUpdate(), and SqlBagOStuff\initSqliteDatabase().

◆ anyChar()

Wikimedia\Rdbms\Platform\ISQLPlatform::anyChar ( )

Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.

Returns
LikeMatch

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ anyString()

Wikimedia\Rdbms\Platform\ISQLPlatform::anyString ( )

◆ bitAnd()

Wikimedia\Rdbms\Platform\ISQLPlatform::bitAnd (   $fieldLeft,
  $fieldRight 
)

◆ bitNot()

Wikimedia\Rdbms\Platform\ISQLPlatform::bitNot (   $field)
Parameters
string | int$field
Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ bitOr()

Wikimedia\Rdbms\Platform\ISQLPlatform::bitOr (   $fieldLeft,
  $fieldRight 
)
Parameters
string | int$fieldLeft
string | int$fieldRight
Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by RevisionDeleteUser\buildSetBitDeletedField().

◆ buildConcat()

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

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by SqlBagOStuff\addCasTokenFields(), and DeleteLocalPasswords\processUsers().

◆ buildGreatest()

Wikimedia\Rdbms\Platform\ISQLPlatform::buildGreatest (   $fields,
  $values 
)

Build a GREATEST 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.

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

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by SiteStatsUpdate\doUpdate().

◆ buildGroupConcatField()

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

Parameters
string$delimGlue to bind the results together
string | array$tableTable name
string$fieldField name
string | array$condsConditions
string | array$join_condsJoin conditions
Returns
string SQL text
Since
1.23

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ buildIntegerCast()

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

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\MySQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by SqlBagOStuff\buildIncrUpsertSet().

◆ buildLeast()

Wikimedia\Rdbms\Platform\ISQLPlatform::buildLeast (   $fields,
  $values 
)

Build a LEAST 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.

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

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ buildLike()

Wikimedia\Rdbms\Platform\ISQLPlatform::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 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 );

Since
1.16 in IDatabase, moved to ISQLPlatform in 1.39
Parameters
array[] | string | LikeMatch$param
string|LikeMatch...$params
Returns
string Fully built LIKE statement

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by RefreshImageMetadata\getConditions(), UppercaseTitlesForUnicodeTransition\getLikeBatches(), and DeleteLocalPasswords\processUsers().

◆ buildSelectSubquery()

Wikimedia\Rdbms\Platform\ISQLPlatform::buildSelectSubquery (   $table,
  $vars,
  $conds = '',
  $fname = __METHOD__,
  $options = [],
  $join_conds = [] 
)

Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery.

See also
IDatabase::selectSQLText()
Parameters
string | array$tableTable name
string | array$varsField names
string | array$condsConditions
string$fnameCaller function name
string | array$optionsQuery options
string | array$join_condsJoin conditions
Returns
Subquery
Since
1.31

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ buildStringCast()

Wikimedia\Rdbms\Platform\ISQLPlatform::buildStringCast (   $field)

◆ buildSubString()

Wikimedia\Rdbms\Platform\ISQLPlatform::buildSubString (   $input,
  $startPosition,
  $length = null 
)

Build a SUBSTRING function.

Behavior for non-ASCII values is undefined.

Parameters
string$inputField name
int$startPositionPositive integer
int | null$lengthNon-negative integer length or null for no limit
Exceptions

Referenced by DeleteLocalPasswords\processUsers().

◆ conditional()

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

Parameters
string | array$condSQL condition expression (yields a boolean)
string$caseTrueExpressionSQL expression to return when the condition is true
string$caseFalseExpressionSQL expression to return when the condition is false
Returns
string SQL fragment

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by SqlBagOStuff\buildIncrUpsertSet(), and SqlBagOStuff\buildUpsertSetForOverwrite().

◆ decodeExpiry()

Wikimedia\Rdbms\Platform\ISQLPlatform::decodeExpiry (   $expiry,
  $format = TS_MW 
)

Decode an expiry time into a DBMS independent format.

Parameters
string$expiryDB timestamp field value for expiry
int$formatTS_* constant, defaults to TS_MW
Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ encodeExpiry()

Wikimedia\Rdbms\Platform\ISQLPlatform::encodeExpiry (   $expiry)

Encode an expiry time into the DBMS dependent format.

Parameters
string$expiryTimestamp for expiry, or the 'infinity' string
Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ factorConds()

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

Parameters
array$condsArrayAn array of associative arrays. The associative array keys represent field names, and the values represent the field values to compare against.
Returns
string SQL expression fragment

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by MediaWiki\Deferred\LinksUpdate\LinksTable\doWrites().

◆ getInfinity()

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

Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ getTableAliases()

Wikimedia\Rdbms\Platform\ISQLPlatform::getTableAliases ( )

Return current table aliases.

Access: internal
only to be used inside rdbms library

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ implicitOrderby()

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

Returns
bool

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ limitResult()

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

Parameters
string$sqlSQL query we will append the limit too
int$limitThe SQL limit
int | bool$offsetThe SQL offset (default false)
Returns
string
Since
1.34 in IDatabase, moved to ISQLPlatform in 1.39

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ makeList()

Wikimedia\Rdbms\Platform\ISQLPlatform::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 ({

See also
IDatabase::select} $conds documentation).

Example usage:

$sql = $db->makeList( [
'rev_page' => $id,
$db->makeList( [ 'rev_minor' => 1, 'rev_len < 500' ], $db::LIST_OR )
const LIST_OR
Definition: Defines.php:46
const LIST_AND
Definition: Defines.php:43

This would set $sql to "rev_page = '$id' AND (rev_minor = 1 OR rev_len < 500)"

Parameters
array$aContaining the data
int$modeIDatabase class constant:
  • IDatabase::LIST_COMMA: Comma separated, no field names
  • IDatabase::LIST_AND: ANDed WHERE clause (without the WHERE).
  • IDatabase::LIST_OR: ORed WHERE clause (without the WHERE)
  • IDatabase::LIST_SET: Comma separated with field names, like a SET clause
  • IDatabase::LIST_NAMES: Comma separated field names
Exceptions
DBErrorIf an error occurs, {
See also
IDatabase::query}
Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by Wikimedia\DependencyStore\SqlModuleDependencyStore\fetchDependencyBlobs(), WatchedItemStore\fetchWatchedItems(), WatchedItemQueryService\getExtraDeletedPageLogEntryRelatedCond(), WatchedItemQueryService\getFromUntilTargetConds(), UppercaseTitlesForUnicodeTransition\getLikeBatches(), WatchedItemQueryService\getStartFromConds(), WANCacheReapUpdate\getTitleChangeEvents(), WatchedItemStore\getVisitingWatchersCondition(), WatchedItemQueryService\getWatchedItemsWithRCInfoQueryConds(), ActorMigrationBase\getWhere(), and MigrateComments\loadCommentIDs().

◆ makeWhereFrom2d()

Wikimedia\Rdbms\Platform\ISQLPlatform::makeWhereFrom2d (   $data,
  $baseKey,
  $subKey 
)

Build a partial where clause from a 2-d array such as used for LinkBatch.

The keys on each level may be either integers or strings, however it's assumed that $baseKey is probably an integer-typed column (i.e. integer keys are unquoted in the SQL) and $subKey is string-typed (i.e. integer keys are quoted as strings in the SQL).

Todo:
Does this actually belong in the library? It seems overly MW-specific.
Parameters
array$dataOrganized as 2-d [ baseKeyVal => [ subKeyVal => [ignored], ... ], ... ]
string$baseKeyField name to match the base-level keys to (eg 'pl_namespace')
string$subKeyField name to match the sub-level keys to (eg 'pl_title')
Returns
string|bool SQL fragment, or false if no items in array

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ selectSQLText()

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

See also
IDatabase::select()
Parameters
string | array$tableTable name
string | array$varsField names
string | array$condsConditions
string$fnameCaller function name
string | array$optionsQuery options
string | array$join_condsJoin conditions
Returns
string SQL query string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseMysqlBase, and Wikimedia\Rdbms\Database.

Referenced by MediaWiki\Revision\RevisionStore\insertRevisionRowOn().

◆ setIndexAliases()

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

Parameters
string[]$aliases
Since
1.31 in IDatabase, moved to ISQLPlatform in 1.39

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ setTableAliases()

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

Parameters
array[]$aliasesMap of (table => (dbname, schema, prefix) map)
Since
1.28 in IDatabase, moved to ISQLPlatform in 1.39

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\Database.

◆ strreplace()

Wikimedia\Rdbms\Platform\ISQLPlatform::strreplace (   $orig,
  $old,
  $new 
)

Returns a SQL expression for simple string replacement (e.g.

REPLACE() in mysql)

Parameters
string$origColumn to modify
string$oldColumn to seek
string$newColumn to replace with
Returns
string

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ tableName()

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

Note
This function does not sanitize user input. It is not safe to use this function to escape user input.
Parameters
string$nameDatabase table name
string$formatOne 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
Returns
string Full database name

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by SqlBagOStuff\initSqliteDatabase().

◆ tableNames()

Wikimedia\Rdbms\Platform\ISQLPlatform::tableNames (   $tables)

Fetch a number of table names into an array This is handy when you need to construct SQL for joins.

Example: list( $user, $watchlist ) = $dbr->tableNames( 'user', 'watchlist' ) ); $sql = "SELECT wl_namespace, wl_title FROM $watchlist, $user WHERE wl_user=user_id AND wl_user=$nameWithQuotes";

Parameters
string...$tables
Returns
array

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ tableNamesN()

Wikimedia\Rdbms\Platform\ISQLPlatform::tableNamesN (   $tables)

Fetch a number of table names into an zero-indexed numerical array This is handy when you need to construct SQL for joins.

Example: list( $user, $watchlist ) = $dbr->tableNamesN( 'user', 'watchlist' ); $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user WHERE wl_user=user_id AND wl_user=$nameWithQuotes";

Parameters
string...$tables
Returns
array

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ timestamp()

◆ timestampOrNull()

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

Parameters
string | int | null$ts
Returns
string|null

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Referenced by User\addToDatabase(), and User\saveSettings().

◆ unionConditionPermutations()

Wikimedia\Rdbms\Platform\ISQLPlatform::unionConditionPermutations (   $table,
  $vars,
array  $permute_conds,
  $extra_conds = '',
  $fname = __METHOD__,
  $options = [],
  $join_conds = [] 
)

Construct a UNION query for permutations of conditions.

Databases sometimes have trouble with queries that have multiple values for multiple condition parameters combined with limits and ordering. This method constructs queries for the Cartesian product of the conditions and unions them all together.

See also
IDatabase::select()
Parameters
string | array$tableTable name
string | array$varsField names
array$permute_condsConditions for the Cartesian product. Keys are field names, values are arrays of the possible values for that field.
string | array$extra_condsAdditional conditions to include in the query.
string$fnameCaller function name
string | array$optionsQuery options. In addition to the options recognized by IDatabase::select(), the following may be used:
  • NOTALL: Set to use UNION instead of UNION ALL.
  • INNER ORDER BY: If specified and supported, subqueries will use this instead of ORDER BY.
string | array$join_condsJoin conditions
Returns
string SQL query string.
Since
1.30

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ unionQueries()

Wikimedia\Rdbms\Platform\ISQLPlatform::unionQueries (   $sqls,
  $all 
)

Construct a UNION query.

This is used for providing overload point for other DB abstractions not compatible with the MySQL syntax.

Parameters
array$sqlsSQL statements to combine
bool$allEither IDatabase::UNION_ALL or IDatabase::UNION_DISTINCT
Returns
string SQL fragment

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

◆ unionSupportsOrderAndLimit()

Wikimedia\Rdbms\Platform\ISQLPlatform::unionSupportsOrderAndLimit ( )

Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.

Returns
bool

Implemented in Wikimedia\Rdbms\Platform\SQLPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.


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