mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
fix: Forge::dropColumn()
always returns false
on SQLite3 driver (#9351)
This commit is contained in:
parent
0fe4bd0ca2
commit
d7ce2ba7d3
@ -778,7 +778,7 @@ class Forge
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $columnNames column names to DROP
|
||||
* @param list<string>|string $columnNames column names to DROP
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
@ -110,6 +110,31 @@ class Forge extends BaseForge
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string>|string $columnNames
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
public function dropColumn(string $table, $columnNames): bool
|
||||
{
|
||||
$columns = is_array($columnNames) ? $columnNames : array_map(trim(...), explode(',', $columnNames));
|
||||
$result = (new Table($this->db, $this))
|
||||
->fromTable($this->db->DBPrefix . $table)
|
||||
->dropColumn($columns)
|
||||
->run();
|
||||
|
||||
if (! $result && $this->db->DBDebug) {
|
||||
throw new DatabaseException(sprintf(
|
||||
'Failed to drop column%s "%s" on "%s" table.',
|
||||
count($columns) > 1 ? 's' : '',
|
||||
implode('", "', $columns),
|
||||
$table,
|
||||
));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $processedFields Processed column definitions
|
||||
* or column names to DROP
|
||||
@ -121,17 +146,6 @@ class Forge extends BaseForge
|
||||
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 = [];
|
||||
|
||||
|
@ -1319,8 +1319,7 @@ final class ForgeTest extends CIUnitTestCase
|
||||
$this->forge->createTable('forge_test_two');
|
||||
|
||||
$this->assertTrue($this->db->fieldExists('name', 'forge_test_two'));
|
||||
|
||||
$this->forge->dropColumn('forge_test_two', 'name');
|
||||
$this->assertTrue($this->forge->dropColumn('forge_test_two', 'name'));
|
||||
|
||||
$this->db->resetDataCache();
|
||||
|
||||
|
@ -31,6 +31,7 @@ Bugs Fixed
|
||||
**********
|
||||
|
||||
- **Common:** Fixed a bug where the ``helper()`` method may throw `FileNotFoundException` on valid namespaced helper.
|
||||
- **Forge:** Fixed an issue where `SQLite3`'s Forge always returns `false` when calling ``dropColumn()``.
|
||||
|
||||
See the repo's
|
||||
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
|
||||
|
@ -1,4 +1,4 @@
|
||||
# total 1686 errors
|
||||
# total 1685 errors
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
@ -1697,11 +1697,6 @@ parameters:
|
||||
count: 1
|
||||
path: ../../system/Database/Forge.php
|
||||
|
||||
-
|
||||
message: '#^Method CodeIgniter\\Database\\Forge\:\:dropColumn\(\) has parameter \$columnNames with no value type specified in iterable type array\.$#'
|
||||
count: 1
|
||||
path: ../../system/Database/Forge.php
|
||||
|
||||
-
|
||||
message: '#^Method CodeIgniter\\Database\\Forge\:\:modifyColumn\(\) has parameter \$fields with no value type specified in iterable type array\.$#'
|
||||
count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user