Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.59% covered (success)
92.59%
25 / 27
91.67% covered (success)
91.67%
22 / 24
CRAP
0.00% covered (danger)
0.00%
0 / 1
SqliteDialect
92.59% covered (success)
92.59%
25 / 27
91.67% covered (success)
91.67%
22 / 24
26.27
0.00% covered (danger)
0.00%
0 / 1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 integer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 bigInteger
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 smallInteger
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 varchar
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 text
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 longText
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 blob
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 boolean
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 timestamp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 date
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 char
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 currentTimestamp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 currentDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 autoIncrement
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createTablePrefix
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 createTableSuffix
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addColumn
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 modifyColumn
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createIndex
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 dropIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supportsColumnPositioning
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supportsCombinedAlter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 quoteIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * SQLite specific SQL dialect.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2023-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2026-01-25
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Setup\Migration\QueryBuilder\Dialect;
21
22use phpMyFAQ\Setup\Migration\QueryBuilder\DialectInterface;
23use RuntimeException;
24
25class SqliteDialect implements DialectInterface
26{
27    public function getType(): string
28    {
29        return 'sqlite3';
30    }
31
32    public function integer(): string
33    {
34        return 'INTEGER';
35    }
36
37    public function bigInteger(): string
38    {
39        return 'INTEGER';
40    }
41
42    public function smallInteger(): string
43    {
44        return 'INTEGER';
45    }
46
47    public function varchar(int $length): string
48    {
49        return "VARCHAR({$length})";
50    }
51
52    public function text(): string
53    {
54        return 'TEXT';
55    }
56
57    public function longText(): string
58    {
59        return 'TEXT';
60    }
61
62    public function blob(): string
63    {
64        return 'BLOB';
65    }
66
67    public function boolean(): string
68    {
69        return 'INTEGER';
70    }
71
72    public function timestamp(): string
73    {
74        return 'DATETIME';
75    }
76
77    public function date(): string
78    {
79        return 'DATE';
80    }
81
82    public function char(int $length): string
83    {
84        return "CHAR({$length})";
85    }
86
87    public function currentTimestamp(): string
88    {
89        return 'CURRENT_TIMESTAMP';
90    }
91
92    public function currentDate(): string
93    {
94        return "(date('now'))";
95    }
96
97    public function autoIncrement(string $columnName): string
98    {
99        return "{$columnName} INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT";
100    }
101
102    public function createTablePrefix(string $tableName, bool $ifNotExists = false): string
103    {
104        $exists = $ifNotExists ? 'IF NOT EXISTS ' : '';
105        return "CREATE TABLE {$exists}{$tableName}";
106    }
107
108    public function createTableSuffix(): string
109    {
110        return '';
111    }
112
113    public function addColumn(string $tableName, string $columnName, string $type, ?string $after = null): string
114    {
115        // SQLite doesn't support AFTER clause
116        return "ALTER TABLE {$tableName} ADD COLUMN {$columnName} {$type}";
117    }
118
119    public function modifyColumn(string $tableName, string $columnName, string $newType): string
120    {
121        // SQLite doesn't support ALTER COLUMN directly
122        // This would require a table rebuild, which is handled separately
123        throw new RuntimeException('SQLite does not support modifying columns. Use table rebuild pattern.');
124    }
125
126    /**
127     * @param string[] $columns
128     */
129    public function createIndex(string $indexName, string $tableName, array $columns, bool $ifNotExists = false): string
130    {
131        $columnList = implode(', ', $columns);
132        $exists = $ifNotExists ? 'IF NOT EXISTS ' : '';
133        return "CREATE INDEX {$exists}{$indexName} ON {$tableName} ({$columnList})";
134    }
135
136    public function dropIndex(string $indexName, string $tableName): string
137    {
138        return "DROP INDEX IF EXISTS {$indexName}";
139    }
140
141    public function supportsColumnPositioning(): bool
142    {
143        return false;
144    }
145
146    public function supportsCombinedAlter(): bool
147    {
148        return false;
149    }
150
151    public function quoteIdentifier(string $identifier): string
152    {
153        return '"' . str_replace(search: '"', replace: '""', subject: $identifier) . '"';
154    }
155}