Skip to content
Open
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();
}
}
}
Loading