Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1684,9 +1684,11 @@ protected function getDriverFunctionPrefix(): string
public function listTables(bool $constrainByPrefix = false)
{
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) {
return $constrainByPrefix
$tables = $constrainByPrefix
? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names'])
: $this->dataCache['table_names'];

return array_values($tables);
}

$sql = $this->_listTables($constrainByPrefix);
Expand Down
20 changes: 19 additions & 1 deletion tests/system/Database/Live/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function dropExtraneousTable(): void
$oldPrefix = $this->db->getPrefix();
$this->db->setPrefix('tmp_');

Database::forge($this->DBGroup)->dropTable('widgets');
Database::forge($this->DBGroup)->dropTable('widgets', true);

$this->db->setPrefix($oldPrefix);
}
Expand Down Expand Up @@ -139,4 +139,22 @@ public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtrane
$this->dropExtraneousTable();
}
}

public function testListTablesReturnsListAfterCachedTableIsDropped(): void
{
try {
$this->createExtraneousTable();

$tables = $this->db->listTables();
$this->assertSame(array_values($tables), $tables);

$this->dropExtraneousTable();

$tables = $this->db->listTables();
$this->assertSame(array_values($tables), $tables);
$this->assertNotContains('tmp_widgets', $tables);
} finally {
$this->dropExtraneousTable();
}
}
}
3 changes: 2 additions & 1 deletion user_guide_src/source/changelogs/v4.7.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ Bugs Fixed
- **CLI:** Fixed a bug where ``CLI::generateDimensions()`` leaked ``tput`` error output (``tput: No value for $TERM and no -T specified``) to stderr when the ``stty`` fallback was reached and the ``TERM`` environment variable was not set.
- **Commands:** Fixed a bug in the ``env`` command where passing options only would cause the command to throw a ``TypeError`` instead of showing the current environment.
- **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown.
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
- **Database:** Fixed a bug where ``BaseConnection::listTables()`` could return a sparse array when using cached table names after a table was dropped.
- **Database:** Fixed a bug where the PostgreSQL driver's ``increment()`` and ``decrement()`` methods were not working for numeric columns.
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
- **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets.
- **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger.
- **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator.
Expand Down
Loading