MediaWiki REL1_39
|
Interface for query language. More...
Public Member Functions | |
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. | |
bitAnd ( $fieldLeft, $fieldRight) | |
bitNot ( $field) | |
bitOr ( $fieldLeft, $fieldRight) | |
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. | |
buildGroupConcatField ( $delim, $table, $field, $conds='', $join_conds=[]) | |
Build a GROUP_CONCAT or equivalent statement for a query. | |
buildIntegerCast ( $field) | |
buildLeast ( $fields, $values) | |
Build a LEAST function statement comparing columns/values. | |
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. | |
buildStringCast ( $field) | |
buildSubString ( $input, $startPosition, $length=null) | |
Build a SUBSTRING function. | |
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. | |
encodeExpiry ( $expiry) | |
Encode an expiry time into the DBMS dependent format. | |
factorConds ( $condsArray) | |
Given an array of condition arrays representing an OR list of AND lists, for example: | |
getInfinity () | |
Find out when 'infinity' is. | |
getTableAliases () | |
Return current table aliases. | |
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. | |
limitResult ( $sql, $limit, $offset=false) | |
Construct a LIMIT query with optional offset. | |
makeList (array $a, $mode=self::LIST_COMMA) | |
Makes an encoded list of strings from an array. | |
makeWhereFrom2d ( $data, $baseKey, $subKey) | |
Build a partial where clause from a 2-d array such as used for LinkBatch. | |
selectSQLText ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Take the same arguments as IDatabase::select() and return the SQL it would use. | |
setIndexAliases (array $aliases) | |
Convert certain index names to alternative names before querying the DB. | |
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 ( $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. | |
unionConditionPermutations ( $table, $vars, array $permute_conds, $extra_conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Construct a UNION query for permutations of conditions. | |
unionQueries ( $sqls, $all) | |
Construct a UNION query. | |
unionSupportsOrderAndLimit () | |
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION. | |
Public Attributes | |
const | QUERY_PSEUDO_PERMANENT = 2 |
Track a TEMPORARY table CREATE as if it was for a permanent table (for testing) | |
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.
Definition at line 33 of file ISQLPlatform.php.
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"
string | $s |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\MySQLPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by SiteStatsUpdate\doUpdate().
Wikimedia\Rdbms\Platform\ISQLPlatform::anyChar | ( | ) |
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::anyString | ( | ) |
Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by DeleteLocalPasswords\processUsers().
Wikimedia\Rdbms\Platform\ISQLPlatform::bitAnd | ( | $fieldLeft, | |
$fieldRight ) |
string | int | $fieldLeft | |
string | int | $fieldRight |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::bitNot | ( | $field | ) |
string | int | $field |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::bitOr | ( | $fieldLeft, | |
$fieldRight ) |
string | int | $fieldLeft | |
string | int | $fieldRight |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::buildConcat | ( | $stringList | ) |
Build a concatenation list to feed into a SQL query.
string[] | $stringList | Raw SQL expression list; caller is responsible for escaping |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by DeleteLocalPasswords\processUsers().
Wikimedia\Rdbms\Platform\ISQLPlatform::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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\MySQLPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
string | string[] | $fields | Name(s) of column(s) with values to compare |
string | int | float | string[] | int[] | float[] | $values | Values to compare |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by SiteStatsUpdate\doUpdate().
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.
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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::buildIntegerCast | ( | $field | ) |
string | $field | Field or column to cast |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\MySQLPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by MigrateActors\migrateLogSearch().
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.
string | string[] | $fields | Name(s) of column(s) with values to compare |
string | int | float | string[] | int[] | float[] | $values | Values to compare |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
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 );
array[] | string | LikeMatch | $param | |
string|LikeMatch | ...$params |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by DeleteLocalPasswords\processUsers().
Wikimedia\Rdbms\Platform\ISQLPlatform::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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::buildStringCast | ( | $field | ) |
string | $field | Field or column to cast |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\MySQLPlatform, Wikimedia\Rdbms\Platform\PostgresPlatform, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::buildSubString | ( | $input, | |
$startPosition, | |||
$length = null ) |
Build a SUBSTRING function.
Behavior for non-ASCII values is undefined.
string | $input | Field name |
int | $startPosition | Positive integer |
int | null | $length | Non-negative integer length or null for no limit |
\InvalidArgumentException
Referenced by DeleteLocalPasswords\processUsers().
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.
string | array | $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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by WatchedItemStore\getWatchedItemsForUser().
Wikimedia\Rdbms\Platform\ISQLPlatform::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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::encodeExpiry | ( | $expiry | ) |
Encode an expiry time into the DBMS dependent format.
string | $expiry | Timestamp for expiry, or the 'infinity' string |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
array | $condsArray | An array of associative arrays. The associative array keys represent field names, and the values represent the field values to compare against. |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by MediaWiki\Deferred\LinksUpdate\LinksTable\doWrites().
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.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::getTableAliases | ( | ) |
Return current table aliases.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
string | $sql | SQL query we will append the limit too |
int | $limit | The SQL limit |
int | false | $offset | The SQL offset (default false) |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
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 ({
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, { |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by WANCacheReapUpdate\getTitleChangeEvents(), and ActorMigrationBase\getWhere().
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).
array | $data | Organized as 2-d [ baseKeyVal => [ subKeyVal => [ignored], ... ], ... ] |
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') |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
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().
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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
string[] | $aliases |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
array[] | $aliases | Map of (table => (dbname, schema, prefix) map) |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseSqlite, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by SqlBagOStuff\createTables().
Wikimedia\Rdbms\Platform\ISQLPlatform::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): [ 'user' => $user, 'watchlist' => $watchlist ] = $dbr->tableNames( 'user', 'watchlist' ); $sql = "SELECT wl_namespace, wl_title FROM $watchlist, $user WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
string | ...$tables |
tableName
or use tableNamesN
instead of calling this function. Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::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): [ $user, $watchlist ] = $dbr->tableNamesN( 'user', 'watchlist' ); $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
string | ...$tables |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::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 |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\PostgresPlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by User\addToDatabase(), WANCacheReapUpdate\getTitleChangeEvents(), JobQueueDB\insertFields(), Title\invalidateCache(), PurgeJobUtils\invalidatePages(), User\makeUpdateConditions(), MediaWiki\Block\DatabaseBlockStore\purgeExpiredBlocks(), Title\purgeExpiredRestrictions(), QueryPage\recache(), User\saveSettings(), and MediaWiki\Revision\RevisionStore\userWasLastToEdit().
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.
string | int | null | $ts |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
Referenced by User\addToDatabase(), and User\saveSettings().
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.
string | array | $table | Table name |
string | array | $vars | Field names |
array | $permute_conds | Conditions for the Cartesian product. Keys are field names, values are arrays of the possible values for that field. |
string | array | $extra_conds | Additional conditions to include in the query. |
string | $fname | Caller function name |
string | array | $options | Query options. In addition to the options recognized by IDatabase::select(), the following may be used:
|
string | array | $join_conds | Join conditions |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Platform\SQLPlatform.
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.
array | $sqls | SQL statements to combine |
bool | $all | Either IDatabase::UNION_ALL or IDatabase::UNION_DISTINCT |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
Wikimedia\Rdbms\Platform\ISQLPlatform::unionSupportsOrderAndLimit | ( | ) |
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DBConnRef, Wikimedia\Rdbms\Platform\SqlitePlatform, and Wikimedia\Rdbms\Platform\SQLPlatform.
const Wikimedia\Rdbms\Platform\ISQLPlatform::QUERY_PSEUDO_PERMANENT = 2 |
Track a TEMPORARY table CREATE as if it was for a permanent table (for testing)
Definition at line 54 of file ISQLPlatform.php.