Skip to content

Commit 2437f2c

Browse files
committed
fix: preserve cached table list shape
1 parent 7446d0b commit 2437f2c

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

system/Database/BaseConnection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,11 @@ protected function getDriverFunctionPrefix(): string
16841684
public function listTables(bool $constrainByPrefix = false)
16851685
{
16861686
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) {
1687-
return $constrainByPrefix
1687+
$tables = $constrainByPrefix
16881688
? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names'])
16891689
: $this->dataCache['table_names'];
1690+
1691+
return array_values($tables);
16901692
}
16911693

16921694
$sql = $this->_listTables($constrainByPrefix);

tests/system/Database/Live/MetadataTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function dropExtraneousTable(): void
7878
$oldPrefix = $this->db->getPrefix();
7979
$this->db->setPrefix('tmp_');
8080

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

8383
$this->db->setPrefix($oldPrefix);
8484
}
@@ -139,4 +139,22 @@ public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtrane
139139
$this->dropExtraneousTable();
140140
}
141141
}
142+
143+
public function testListTablesReturnsListAfterCachedTableIsDropped(): void
144+
{
145+
try {
146+
$this->createExtraneousTable();
147+
148+
$tables = $this->db->listTables();
149+
$this->assertSame(array_values($tables), $tables);
150+
151+
$this->dropExtraneousTable();
152+
153+
$tables = $this->db->listTables();
154+
$this->assertSame(array_values($tables), $tables);
155+
$this->assertNotContains('tmp_widgets', $tables);
156+
} finally {
157+
$this->dropExtraneousTable();
158+
}
159+
}
142160
}

0 commit comments

Comments
 (0)