42 return '(' . implode(
') || (', $stringList ) .
')';
51 $glue = $all ?
' UNION ALL ' :
' UNION ';
53 return implode( $glue, $sqls );
65 $params = [ $input, $startPosition ];
66 if ( $length !==
null ) {
69 return 'SUBSTR(' . implode(
',', $params ) .
')';
78 return 'CAST ( ' . $field .
' AS TEXT )';
81 public function tableName( $name, $format =
'quoted' ) {
82 if ( preg_match(
'/^sqlite_[a-z_]+$/', $name ) ) {
87 return parent::tableName( $name, $format );
92 foreach ( $options as $k => $v ) {
93 if ( is_numeric( $k ) && ( $v ===
'FOR UPDATE' || $v ===
'LOCK IN SHARE MODE' ) ) {
98 return parent::makeSelectOptions( $options );
102 $delim, $table, $field, $conds =
'', $join_conds = []
104 $fld =
"group_concat($field," . $this->quoter->addQuotes( $delim ) .
')';
106 return '(' . $this->
selectSQLText( $table, $fld, $conds,
null, [], $join_conds ) .
')';
110 return [
'INSERT OR IGNORE INTO',
'' ];
118 $options = parent::makeUpdateOptionsArray( $options );
119 $options = $this->rewriteIgnoreKeyword( $options );
128 private function rewriteIgnoreKeyword( $options ) {
129 # SQLite uses OR IGNORE not just IGNORE
130 foreach ( $options as $k => $v ) {
131 if ( $v ==
'IGNORE' ) {
132 $options[$k] =
'OR IGNORE';
141 return "DROP TABLE " . $this->
tableName( $table );
145 return parent::isTransactableQuery( $sql ) && !in_array(
147 [
'ATTACH',
'PRAGMA' ],
153 return parent::isWriteQuery( $sql, $flags ) && !preg_match(
'/^(ATTACH|PRAGMA)\b/i', $sql );
161 $s = parent::replaceVars( $s );
162 if ( preg_match(
'/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
166 $s = preg_replace(
'/\b(var)?binary(\(\d+\))/i',
'BLOB', $s );
168 $s = preg_replace(
'/\b(un)?signed\b/i',
'', $s );
170 $s = preg_replace(
'/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i',
'INTEGER', $s );
173 '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i',
178 $s = preg_replace(
'/\b(var)?char\s*\(.*?\)/i',
'TEXT', $s );
180 $s = preg_replace(
'/\b(tiny|medium|long)text\b/i',
'TEXT', $s );
182 $s = preg_replace(
'/\b(tiny|small|medium|long|)blob\b/i',
'BLOB', $s );
184 $s = preg_replace(
'/\bbool(ean)?\b/i',
'INTEGER', $s );
186 $s = preg_replace(
'/\b(datetime|timestamp)\b/i',
'TEXT', $s );
188 $s = preg_replace(
'/\benum\s*\([^)]*\)/i',
'TEXT', $s );
190 $s = preg_replace(
'/\bbinary\b/i',
'', $s );
192 $s = preg_replace(
'/\bauto_increment\b/i',
'AUTOINCREMENT', $s );
194 $s = preg_replace(
'/\)[^);]*(;?)\s*$/',
')\1', $s );
196 $s = preg_replace(
'/primary key (.*?) autoincrement/i',
'PRIMARY KEY AUTOINCREMENT $1', $s );
197 } elseif ( preg_match(
'/^\s*CREATE (\s*(?:UNIQUE|FULLTEXT)\s+)?INDEX/i', $s ) ) {
199 $s = preg_replace(
'/\(\d+\)/',
'', $s );
201 $s = preg_replace(
'/\bfulltext\b/i',
'', $s );
202 } elseif ( preg_match(
'/^\s*DROP INDEX/i', $s ) ) {
204 $s = preg_replace(
'/\sON\s+[^\s]*/i',
'', $s );
205 } elseif ( preg_match(
'/^\s*INSERT IGNORE\b/i', $s ) ) {
207 $s = preg_replace(
'/^\s*INSERT IGNORE\b/i',
'INSERT OR IGNORE', $s );