Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2677,12 +2677,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/Forge.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\Forge\\:\\:dropColumn\\(\\) has parameter \\$columnNames with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/Forge.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\Forge\\:\\:modifyColumn\\(\\) has parameter \\$fields with no value type specified in iterable type array\\.$#',
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ public function addColumn(string $table, $fields): bool
}

/**
* @param array|string $columnNames column names to DROP
* @param list<string>|string $columnNames column names to DROP
*
* @return bool
*
Expand Down
37 changes: 26 additions & 11 deletions system/Database/SQLite3/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ public function dropDatabase(string $dbName): bool
protected function _alterTable(string $alterType, string $table, $processedFields)
{
switch ($alterType) {
case 'DROP':
$columnNamesToDrop = $processedFields;

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

$sqlTable->fromTable($table)
->dropColumn($columnNamesToDrop)
->run();

return ''; // Why empty string?

case 'CHANGE':
$fieldsToModify = [];

Expand Down Expand Up @@ -164,6 +153,32 @@ protected function _alterTable(string $alterType, string $table, $processedField
}
}

/**
* @param list<string>|string $columnNames column names to DROP
*
* @return bool
*
* @throws DatabaseException
*/
public function dropColumn(string $table, $columnNames)
{
$sqlTable = new Table($this->db, $this);

$sqlExecuteResult = $sqlTable->fromTable($this->db->DBPrefix . $table)
->dropColumn($columnNames)
->run();

if ($sqlExecuteResult === false) {
if ($this->db->DBDebug) {
throw new DatabaseException('This feature is not available for the database you are using.');
}

return false;
}

return $sqlExecuteResult;
}

/**
* Process column
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,8 @@ public function testDropColumn(): void

$this->assertTrue($this->db->fieldExists('name', 'forge_test_two'));

$this->forge->dropColumn('forge_test_two', 'name');
$result = $this->forge->dropColumn('forge_test_two', 'name');
$this->assertTrue($result);

$this->db->resetDataCache();

Expand Down
Empty file added writable/test_com.sitedb.web
Empty file.