MediaWiki master
SqlitePlatform.php
Go to the documentation of this file.
1<?php
21
23
29 public function buildGreatest( $fields, $values ) {
30 return $this->buildSuperlative( 'MAX', $fields, $values );
31 }
32
33 public function buildLeast( $fields, $values ) {
34 return $this->buildSuperlative( 'MIN', $fields, $values );
35 }
36
43 public function buildConcat( $stringList ) {
44 return '(' . implode( ') || (', $stringList ) . ')';
45 }
46
53 public function unionQueries( $sqls, $all, $options = [] ) {
54 $glue = $all ? ' UNION ALL ' : ' UNION ';
55
56 return implode( $glue, $sqls );
57 }
58
62 public function unionSupportsOrderAndLimit() {
63 return false;
64 }
65
66 public function buildSubstring( $input, $startPosition, $length = null ) {
67 $this->assertBuildSubstringParams( $startPosition, $length );
68 $params = [ $input, $startPosition ];
69 if ( $length !== null ) {
70 $params[] = $length;
71 }
72 return 'SUBSTR(' . implode( ',', $params ) . ')';
73 }
74
80 public function buildStringCast( $field ) {
81 return 'CAST ( ' . $field . ' AS TEXT )';
82 }
83
84 public function tableName( string $name, $format = 'quoted' ) {
85 if ( preg_match( '/^sqlite_[a-z_]+$/', $name ) ) {
86 // Such names are reserved for internal SQLite tables
87 return $name;
88 }
89
90 return parent::tableName( $name, $format );
91 }
92
93 protected function makeSelectOptions( array $options ) {
94 // Remove problematic options that the base implementation converts to SQL
95 foreach ( $options as $k => $v ) {
96 if ( is_numeric( $k ) && ( $v === 'FOR UPDATE' || $v === 'LOCK IN SHARE MODE' ) ) {
97 $options[$k] = '';
98 }
99 }
100
101 return parent::makeSelectOptions( $options );
102 }
103
104 public function buildGroupConcatField(
105 $delim, $table, $field, $conds = '', $join_conds = []
106 ) {
107 $fld = "group_concat($field," . $this->quoter->addQuotes( $delim ) . ')';
108
109 return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
110 }
111
113 return [ 'INSERT OR IGNORE INTO', '' ];
114 }
115
120 protected function makeUpdateOptionsArray( $options ) {
121 $options = parent::makeUpdateOptionsArray( $options );
122 $options = $this->rewriteIgnoreKeyword( $options );
123
124 return $options;
125 }
126
131 private function rewriteIgnoreKeyword( $options ) {
132 # SQLite uses OR IGNORE not just IGNORE
133 foreach ( $options as $k => $v ) {
134 if ( $v == 'IGNORE' ) {
135 $options[$k] = 'OR IGNORE';
136 }
137 }
138
139 return $options;
140 }
141
142 public function dropTableSqlText( $table ) {
143 // No CASCADE support; https://www.sqlite.org/lang_droptable.html
144 return "DROP TABLE " . $this->tableName( $table );
145 }
146
147 public function isTransactableQuery( Query $sql ) {
148 return parent::isTransactableQuery( $sql ) && !in_array(
149 $sql->getVerb(),
150 [ 'ATTACH', 'PRAGMA' ],
151 true
152 );
153 }
154}
array $params
The job parameters.
buildSuperlative( $sqlfunc, $fields, $values)
Build a superlative function statement comparing columns/values.
assertBuildSubstringParams( $startPosition, $length)
Check type and bounds for parameters to self::buildSubstring()
selectSQLText( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Take the same arguments as IDatabase::select() and return the SQL it would use.
buildConcat( $stringList)
Build a concatenation list to feed into a SQL query.
buildGreatest( $fields, $values)
Build a GREATEST function statement comparing columns/values.Integer and float values in $values will...
buildLeast( $fields, $values)
Build a LEAST function statement comparing columns/values.Integer and float values in $values will no...
isTransactableQuery(Query $sql)
Determine whether a SQL statement is sensitive to isolation level.
unionQueries( $sqls, $all, $options=[])
tableName(string $name, $format='quoted')
Format a table name ready for use in constructing an SQL query.
buildSubstring( $input, $startPosition, $length=null)
to override
buildGroupConcatField( $delim, $table, $field, $conds='', $join_conds=[])
Build a GROUP_CONCAT or equivalent statement for a query.
makeSelectOptions(array $options)
Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the quer...
Holds information on Query to be executed.
Definition Query.php:31