MediaWiki  master
Wikimedia\Rdbms\Platform\SqlitePlatform Class Reference
Inheritance diagram for Wikimedia\Rdbms\Platform\SqlitePlatform:
Collaboration diagram for Wikimedia\Rdbms\Platform\SqlitePlatform:

Public Member Functions

 buildConcat ( $stringList)
 Build a concatenation list to feed into a SQL query. More...
 
 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
More...
 
 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
Stability: stable
to override
More...
 
 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
More...
 
 buildStringCast ( $field)
 
 buildSubstring ( $input, $startPosition, $length=null)
 
Stability: stable
to override
More...
 
 dropTableSqlText ( $table)
 
 isTransactableQuery ( $sql)
 Determine whether a SQL statement is sensitive to isolation level. More...
 
 isWriteQuery ( $sql, $flags)
 Determine whether a query writes to the DB. More...
 
 replaceVars ( $s)
 
 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
Stability: stable
to override
More...
 
 unionQueries ( $sqls, $all)
 
 unionSupportsOrderAndLimit ()
 
- 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.table, column, database) for use in a SQL queryDepending on the database this will either be backticks or "double quotes"
Parameters
string$s
Returns
string
Since
1.33
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...
 
 assertValidUpsertSetArray (array $set, array $identityKey, array $rows)
 
 bitAnd ( $fieldLeft, $fieldRight)
 
Parameters
string | int$fieldLeft
string | int$fieldRight
Returns
string
More...
 
 bitNot ( $field)
 
Parameters
string | int$field
Returns
string
More...
 
 bitOr ( $fieldLeft, $fieldRight)
 
Parameters
string | int$fieldLeft
string | int$fieldRight
Returns
string
More...
 
 buildComparison (string $op, array $conds)
 Build a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g. More...
 
 buildExcludedValue ( $column)
 Build a reference to a column value from the conflicting proposed upsert() row. More...
 
 buildIntegerCast ( $field)
 
Parameters
string$fieldField or column to cast
Returns
string
Since
1.31 in IDatabase, moved to ISQLPlatform in 1.39
More...
 
 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
More...
 
 buildSelectSubquery ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery. More...
 
 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
More...
 
 decodeExpiry ( $expiry, $format=TS_MW)
 Decode an expiry time into a DBMS independent format. More...
 
 deleteJoinSqlText ( $delTable, $joinTable, $delVar, $joinVar, $conds)
 
 deleteSqlText ( $table, $conds)
 
 dispatchingInsertSqlText ( $table, $rows, $options)
 
 encodeExpiry ( $expiry)
 Encode an expiry time into the DBMS dependent format. More...
 
 escapeLikeInternal ( $s, $escapeChar='`')
 
 extractSingleFieldFromList ( $var)
 
 factorConds ( $condsArray)
 Given an array of condition arrays representing an OR list of AND lists, for example: More...
 
 fieldNameWithAlias ( $name, $alias=false)
 Get an aliased field name e.g. More...
 
 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
More...
 
 getQueryVerb ( $sql)
 
 getTableAliases ()
 
 ignoreIndexClause ( $index)
 IGNORE INDEX clause. 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.
Returns
bool
More...
 
 indexName ( $index)
 Allows for index remapping in queries where this is not consistent across DBMS. More...
 
 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. More...
 
 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 | false$offsetThe SQL offset (default false)
Returns
string
Since
1.34 in IDatabase, moved to ISQLPlatform in 1.39
More...
 
 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. More...
 
 makeKeyCollisionCondition (array $rows, array $uniqueKey)
 Build an SQL condition to find rows with matching key values to those in $rows. 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...
 
 normalizeConditions ( $conds, $fname)
 
 normalizeOptions ( $options)
 
 normalizeUpsertParams ( $uniqueKeys, &$rows)
 Validate and normalize parameters to upsert() or replace() More...
 
 qualifiedTableComponents ( $name)
 Get the table components needed for a query given the currently selected database. More...
 
 releaseSavepointSqlText ( $identifier)
 
 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().
See also
IDatabase::select()
Parameters
string | array$tableTable name(s)
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
More...
 
 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.
Parameters
string[]$aliases
Since
1.31 in IDatabase, moved to ISQLPlatform in 1.39
More...
 
 setPrefix ( $prefix)
 
 setSchemaVars ( $vars)
 Set schema variables to be used when streaming commands from SQL files or stdin. 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.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
More...
 
 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
More...
 
 tableNames (... $tables)
 Fetch a number of table names into an associative array. More...
 
 tableNamesN (... $tables)
 Fetch a number of table names into a zero-indexed numerical array. 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.The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.
Parameters
string | int$ts
Returns
string
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...
 
 unlockSQLText ( $lockName)
 
 updateSqlText ( $table, $set, $conds, $options)
 
 useIndexClause ( $index)
 USE INDEX clause. More...
 
- Public Member Functions inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
 buildSubString ( $input, $startPosition, $length=null)
 Build a SUBSTRING function. More...
 

Protected Member Functions

 makeInsertNonConflictingVerbAndOptions ()
 
 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. More...
 
 makeUpdateOptionsArray ( $options)
 
- Protected Member Functions inherited from Wikimedia\Rdbms\Platform\SQLPlatform
 assertBuildSubstringParams ( $startPosition, $length)
 Check type and bounds for parameters to self::buildSubstring() More...
 
 assertConditionIsNotEmpty ( $conds, string $fname, bool $deprecate)
 Check type and bounds conditions parameters for update. More...
 
 assertValidUpsertRowArray (array $rows, array $identityKey)
 
 buildSuperlative ( $sqlfunc, $fields, $values)
 Build a superlative function statement comparing columns/values. More...
 
 fieldHasBit (int $flags, int $bit)
 
 fieldNamesWithAlias ( $fields)
 Gets an array of aliased field names. More...
 
 getDefaultSchemaVars ()
 Get schema variables to use if none have been set via setSchemaVars(). More...
 
 getSchemaVars ()
 Get schema variables. More...
 
 makeGroupByWithHaving ( $options)
 Returns an optional GROUP BY with an optional HAVING. More...
 
 makeOrderBy ( $options)
 Returns an optional ORDER BY. More...
 
 makeUpdateOptions ( $options)
 Make UPDATE options for the Database::update function. More...
 
 normalizeJoinType (string $joinType)
 Validate and normalize a join type. More...
 
 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. More...
 
 tableNameWithAlias ( $table, $alias=false)
 Get an aliased table name. More...
 

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) More...
 
- Protected Attributes inherited from Wikimedia\Rdbms\Platform\SQLPlatform
DatabaseDomain null $currentDomain
 
callable $errorLogger
 Error logging callback. More...
 
string[] $indexAliases = []
 Current map of (index alias => index) More...
 
LoggerInterface $logger
 
DbQuoter $quoter
 
array null $schemaVars
 Current variables use for schema element placeholders. More...
 
array[] $tableAliases = []
 Current map of (table => (dbname, schema, prefix) map) More...
 

Detailed Description

Since
1.38
See also
ISQLPlatform

Definition at line 26 of file SqlitePlatform.php.

Member Function Documentation

◆ buildConcat()

Wikimedia\Rdbms\Platform\SqlitePlatform::buildConcat (   $stringList)

Build a concatenation list to feed into a SQL query.

Parameters
string[]$stringList
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 41 of file SqlitePlatform.php.

◆ buildGreatest()

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

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 27 of file SqlitePlatform.php.

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

◆ buildGroupConcatField()

Wikimedia\Rdbms\Platform\SqlitePlatform::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
Stability: stable
to override

Stability: stable
to override

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 101 of file SqlitePlatform.php.

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

◆ buildLeast()

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

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 31 of file SqlitePlatform.php.

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

◆ buildStringCast()

Wikimedia\Rdbms\Platform\SqlitePlatform::buildStringCast (   $field)
Parameters
string$fieldField or column to cast
Returns
string
Since
1.28

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 77 of file SqlitePlatform.php.

◆ buildSubstring()

Wikimedia\Rdbms\Platform\SqlitePlatform::buildSubstring (   $input,
  $startPosition,
  $length = null 
)

Stability: stable
to override

Stability: stable
to override

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 63 of file SqlitePlatform.php.

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

◆ dropTableSqlText()

Wikimedia\Rdbms\Platform\SqlitePlatform::dropTableSqlText (   $table)

◆ isTransactableQuery()

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

Stability: stable
to override
Parameters
string$sql
Returns
bool

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 144 of file SqlitePlatform.php.

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

◆ isWriteQuery()

Wikimedia\Rdbms\Platform\SqlitePlatform::isWriteQuery (   $sql,
  $flags 
)

Determine whether a query writes to the DB.

When in doubt, this returns true.

Main use cases:

  • Subsequent web requests should not need to wait for replication from the primary position seen by this web request, unless this request made changes to the primary DB. This is handled by ChronologyProtector by checking doneWrites() at the end of the request. doneWrites() returns true if any query set lastWriteTime; which query() does based on isWriteQuery().
  • Reject write queries to replica DBs, in query().
Parameters
string$sqlSQL query
int$flagsQuery flags to query()
Returns
bool

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 152 of file SqlitePlatform.php.

◆ makeInsertNonConflictingVerbAndOptions()

Wikimedia\Rdbms\Platform\SqlitePlatform::makeInsertNonConflictingVerbAndOptions ( )
protected
Stability: stable
to override
Returns
string[] ("INSERT"-style SQL verb, "ON CONFLICT"-style clause or "")
Since
1.35

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 109 of file SqlitePlatform.php.

◆ makeSelectOptions()

Wikimedia\Rdbms\Platform\SqlitePlatform::makeSelectOptions ( array  $options)
protected

Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.

See also
Database::select()
Stability: stable
to override
Parameters
array$optionsAssociative array of options to be turned into an SQL query, valid keys are listed in the function.
Returns
string[] (START OPTIONS, PRE-LIMIT TAIL, POST-LIMIT TAIL)

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 90 of file SqlitePlatform.php.

◆ makeUpdateOptionsArray()

Wikimedia\Rdbms\Platform\SqlitePlatform::makeUpdateOptionsArray (   $options)
protected
Parameters
array$options
Returns
array

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 117 of file SqlitePlatform.php.

◆ replaceVars()

Wikimedia\Rdbms\Platform\SqlitePlatform::replaceVars (   $s)
Parameters
string$s
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 160 of file SqlitePlatform.php.

References $s.

◆ tableName()

Wikimedia\Rdbms\Platform\SqlitePlatform::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
Stability: stable
to override

Stability: stable
to override

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 81 of file SqlitePlatform.php.

Referenced by Wikimedia\Rdbms\Platform\SqlitePlatform\dropTableSqlText().

◆ unionQueries()

Wikimedia\Rdbms\Platform\SqlitePlatform::unionQueries (   $sqls,
  $all 
)
Parameters
string[]$sqls
bool$allWhether to "UNION ALL" or not
Returns
string

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 50 of file SqlitePlatform.php.

◆ unionSupportsOrderAndLimit()

Wikimedia\Rdbms\Platform\SqlitePlatform::unionSupportsOrderAndLimit ( )
Returns
bool

Reimplemented from Wikimedia\Rdbms\Platform\SQLPlatform.

Definition at line 59 of file SqlitePlatform.php.


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