1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Sqlite; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Exception\NotSupportedException; |
8
|
|
|
use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder; |
9
|
|
|
use Yiisoft\Db\Schema\Builder\ColumnInterface; |
10
|
|
|
|
11
|
|
|
use function count; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Implements a (Data Definition Language) SQL statements for SQLite Server. |
15
|
|
|
*/ |
16
|
|
|
final class DDLQueryBuilder extends AbstractDDLQueryBuilder |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
20
|
|
|
*/ |
21
|
4 |
|
public function addCheck(string $table, string $name, string $expression): string |
22
|
|
|
{ |
23
|
4 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
28
|
|
|
*/ |
29
|
3 |
|
public function addCommentOnColumn(string $table, string $column, string $comment): string |
30
|
|
|
{ |
31
|
3 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
36
|
|
|
*/ |
37
|
2 |
|
public function addCommentOnTable(string $table, string $comment): string |
38
|
|
|
{ |
39
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
44
|
|
|
*/ |
45
|
3 |
|
public function addDefaultValue(string $table, string $name, string $column, mixed $value): string |
46
|
|
|
{ |
47
|
3 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
52
|
|
|
*/ |
53
|
6 |
|
public function addForeignKey( |
54
|
|
|
string $table, |
55
|
|
|
string $name, |
56
|
|
|
array|string $columns, |
57
|
|
|
string $referenceTable, |
58
|
|
|
array|string $referenceColumns, |
59
|
|
|
string $delete = null, |
60
|
|
|
string $update = null |
61
|
|
|
): string { |
62
|
6 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
67
|
|
|
*/ |
68
|
6 |
|
public function addPrimaryKey(string $table, string $name, array|string $columns): string |
69
|
|
|
{ |
70
|
6 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
75
|
|
|
*/ |
76
|
6 |
|
public function addUnique(string $table, string $name, array|string $columns): string |
77
|
|
|
{ |
78
|
6 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
83
|
|
|
*/ |
84
|
2 |
|
public function alterColumn(string $table, string $column, ColumnInterface|string $type): string |
85
|
|
|
{ |
86
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
87
|
|
|
} |
88
|
|
|
|
89
|
2 |
|
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string |
90
|
|
|
{ |
91
|
2 |
|
return 'PRAGMA foreign_keys=' . (int) $check; |
92
|
|
|
} |
93
|
|
|
|
94
|
11 |
|
public function createIndex( |
95
|
|
|
string $table, |
96
|
|
|
string $name, |
97
|
|
|
array|string $columns, |
98
|
|
|
string $indexType = null, |
99
|
|
|
string $indexMethod = null |
100
|
|
|
): string { |
101
|
11 |
|
$tableParts = explode('.', $table); |
102
|
|
|
|
103
|
11 |
|
$schema = null; |
104
|
11 |
|
if (count($tableParts) === 2) { |
105
|
1 |
|
[$schema, $table] = $tableParts; |
106
|
|
|
} |
107
|
|
|
|
108
|
11 |
|
return 'CREATE ' . (!empty($indexType) ? $indexType . ' ' : '') . 'INDEX ' |
109
|
11 |
|
. $this->quoter->quoteTableName((!empty($schema) ? $schema . '.' : '') . $name) |
110
|
11 |
|
. ' ON ' |
111
|
11 |
|
. $this->quoter->quoteTableName($table) |
112
|
11 |
|
. ' (' . $this->queryBuilder->buildColumns($columns) . ')'; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
117
|
|
|
*/ |
118
|
1 |
|
public function dropCheck(string $table, string $name): string |
119
|
|
|
{ |
120
|
1 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
125
|
|
|
*/ |
126
|
2 |
|
public function dropColumn(string $table, string $column): string |
127
|
|
|
{ |
128
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
133
|
|
|
*/ |
134
|
2 |
|
public function dropCommentFromColumn(string $table, string $column): string |
135
|
|
|
{ |
136
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
141
|
|
|
*/ |
142
|
2 |
|
public function dropCommentFromTable(string $table): string |
143
|
|
|
{ |
144
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
149
|
|
|
*/ |
150
|
2 |
|
public function dropDefaultValue(string $table, string $name): string |
151
|
|
|
{ |
152
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
157
|
|
|
*/ |
158
|
2 |
|
public function dropForeignKey(string $table, string $name): string |
159
|
|
|
{ |
160
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
161
|
|
|
} |
162
|
|
|
|
163
|
2 |
|
public function dropIndex(string $table, string $name): string |
164
|
|
|
{ |
165
|
2 |
|
return 'DROP INDEX ' . $this->quoter->quoteTableName($name); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
170
|
|
|
*/ |
171
|
2 |
|
public function dropPrimaryKey(string $table, string $name): string |
172
|
|
|
{ |
173
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
178
|
|
|
*/ |
179
|
2 |
|
public function dropUnique(string $table, string $name): string |
180
|
|
|
{ |
181
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @throws NotSupportedException SQLite doesn't support this method. |
186
|
|
|
*/ |
187
|
2 |
|
public function renameColumn(string $table, string $oldName, string $newName): string |
188
|
|
|
{ |
189
|
2 |
|
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); |
190
|
|
|
} |
191
|
|
|
|
192
|
3 |
|
public function renameTable(string $oldName, string $newName): string |
193
|
|
|
{ |
194
|
3 |
|
return 'ALTER TABLE ' |
195
|
3 |
|
. $this->quoter->quoteTableName($oldName) |
196
|
3 |
|
. ' RENAME TO ' |
197
|
3 |
|
. $this->quoter->quoteTableName($newName); |
198
|
|
|
} |
199
|
|
|
|
200
|
2 |
|
public function truncateTable(string $table): string |
201
|
|
|
{ |
202
|
2 |
|
return 'DELETE FROM ' . $this->quoter->quoteTableName($table); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|