Skip to content

Commit 0b55fc4

Browse files
committed
fix: override the dropColumn() function.
1 parent a8cfb51 commit 0b55fc4

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

system/Database/SQLite3/Forge.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function dropDatabase(string $dbName): bool
115115
* or column names to DROP
116116
*
117117
* @return array|string|null
118-
* @return list<string>|string|null SQL string or null
118+
* @return bool|list<string>|string|null SQL execute result or null
119119
* @phpstan-return ($alterType is 'DROP' ? string : list<string>|null)
120120
*/
121121
protected function _alterTable(string $alterType, string $table, $processedFields)
@@ -126,13 +126,11 @@ protected function _alterTable(string $alterType, string $table, $processedField
126126

127127
$sqlTable = new Table($this->db, $this);
128128

129-
$sqlExecuteResult = $sqlTable->fromTable($table)
129+
return $sqlTable->fromTable($table)
130130
->dropColumn($columnNamesToDrop)
131131
->run();
132132

133-
// Return the execute result with string type.
134-
return '' . $sqlExecuteResult;
135-
133+
// Return the execute result with boolean type.
136134
case 'CHANGE':
137135
$fieldsToModify = [];
138136

@@ -153,18 +151,42 @@ protected function _alterTable(string $alterType, string $table, $processedField
153151
$fieldsToModify[] = $field;
154152
}
155153

156-
(new Table($this->db, $this))
154+
return (new Table($this->db, $this))
157155
->fromTable($table)
158156
->modifyColumn($fieldsToModify)
159157
->run();
160158

161-
return null; // Why null?
162-
163159
default:
164160
return parent::_alterTable($alterType, $table, $processedFields);
165161
}
166162
}
167163

164+
/**
165+
* @param array|string $columnNames column names to DROP
166+
*
167+
* @return bool
168+
*
169+
* @throws DatabaseException
170+
*/
171+
public function dropColumn(string $table, $columnNames)
172+
{
173+
$sqlExecuteResult = $this->_alterTable('DROP', $this->db->DBPrefix . $table, $columnNames);
174+
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+
}
180+
181+
return false;
182+
}
183+
184+
return $sqlExecuteResult;
185+
}
186+
187+
return $this->db->query($sqlExecuteResult);
188+
}
189+
168190
/**
169191
* Process column
170192
*/

0 commit comments

Comments
 (0)