Skip to content

Commit 7727d15

Browse files
committed
feat: refactor dropColum function.
1 parent 4a61f50 commit 7727d15

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

system/Database/SQLite3/Forge.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,12 @@ public function dropDatabase(string $dbName): bool
115115
* or column names to DROP
116116
*
117117
* @return array|string|null
118-
* @return bool|list<string>|string|null SQL execute result or null
118+
* @return list<string>|string|null SQL string or null
119119
* @phpstan-return ($alterType is 'DROP' ? string : list<string>|null)
120120
*/
121121
protected function _alterTable(string $alterType, string $table, $processedFields)
122122
{
123123
switch ($alterType) {
124-
case 'DROP':
125-
$columnNamesToDrop = $processedFields;
126-
127-
$sqlTable = new Table($this->db, $this);
128-
129-
return $sqlTable->fromTable($table)
130-
->dropColumn($columnNamesToDrop)
131-
->run();
132-
133-
// Return the execute result with boolean type.
134124
case 'CHANGE':
135125
$fieldsToModify = [];
136126

@@ -151,11 +141,13 @@ protected function _alterTable(string $alterType, string $table, $processedField
151141
$fieldsToModify[] = $field;
152142
}
153143

154-
return (new Table($this->db, $this))
144+
(new Table($this->db, $this))
155145
->fromTable($table)
156146
->modifyColumn($fieldsToModify)
157147
->run();
158148

149+
return null; // Why null?
150+
159151
default:
160152
return parent::_alterTable($alterType, $table, $processedFields);
161153
}
@@ -170,21 +162,21 @@ protected function _alterTable(string $alterType, string $table, $processedField
170162
*/
171163
public function dropColumn(string $table, $columnNames)
172164
{
173-
$sqlExecuteResult = $this->_alterTable('DROP', $this->db->DBPrefix . $table, $columnNames);
165+
$sqlTable = new Table($this->db, $this);
174166

175-
if (is_bool($sqlExecuteResult) === true) {
176-
if ($sqlExecuteResult === false) {
177-
if ($this->db->DBDebug) {
178-
throw new DatabaseException('This feature is not available for the database you are using.');
179-
}
167+
$sqlExecuteResult = $sqlTable->fromTable($this->db->DBPrefix . $table)
168+
->dropColumn($columnNames)
169+
->run();
180170

181-
return false;
171+
if ($sqlExecuteResult === false) {
172+
if ($this->db->DBDebug) {
173+
throw new DatabaseException('This feature is not available for the database you are using.');
182174
}
183175

184-
return $sqlExecuteResult;
176+
return false;
185177
}
186178

187-
return $this->db->query($sqlExecuteResult);
179+
return $sqlExecuteResult;
188180
}
189181

190182
/**

0 commit comments

Comments
 (0)