diff --git a/system/Commands/Database/ShowTableInfo.php b/system/Commands/Database/ShowTableInfo.php index 954cf33aaa1f..844cbd4ab358 100644 --- a/system/Commands/Database/ShowTableInfo.php +++ b/system/Commands/Database/ShowTableInfo.php @@ -200,7 +200,7 @@ private function showDataOfTable(string $tableName, int $limitRows, int $limitFi CLI::newLine(); $this->removeDBPrefix(); - $thead = $this->db->getFieldNames(TableName::fromActualName($this->db, $tableName)); + $thead = $this->db->getFieldNames(TableName::fromActualName($this->db->DBPrefix, $tableName)); $this->restoreDBPrefix(); // If there is a field named `id`, sort by it. @@ -278,7 +278,7 @@ private function makeTableRows( $this->tbody = []; $this->removeDBPrefix(); - $builder = $this->db->table(TableName::fromActualName($this->db, $tableName)); + $builder = $this->db->table(TableName::fromActualName($this->db->DBPrefix, $tableName)); $builder->limit($limitRows); if ($sortField !== null) { $builder->orderBy($sortField, $this->sortDesc ? 'DESC' : 'ASC'); diff --git a/system/Database/TableName.php b/system/Database/TableName.php index 44f916809c52..fcceaa835e6f 100644 --- a/system/Database/TableName.php +++ b/system/Database/TableName.php @@ -44,10 +44,10 @@ protected function __construct( * @param string $table Table name (w/o DB prefix) * @param string $alias Alias name */ - public static function create(BaseConnection $db, string $table, string $alias = ''): self + public static function create(string $dbPrefix, string $table, string $alias = ''): self { return new self( - $db->DBPrefix . $table, + $dbPrefix . $table, $table, '', '', @@ -61,9 +61,9 @@ public static function create(BaseConnection $db, string $table, string $alias = * @param string $actualTable Actual table name with DB prefix * @param string $alias Alias name */ - public static function fromActualName(BaseConnection $db, string $actualTable, string $alias = ''): self + public static function fromActualName(string $dbPrefix, string $actualTable, string $alias = ''): self { - $prefix = $db->DBPrefix; + $prefix = $dbPrefix; $logicalTable = ''; if (str_starts_with($actualTable, $prefix)) { @@ -87,14 +87,14 @@ public static function fromActualName(BaseConnection $db, string $actualTable, s * @param string $alias Alias name */ public static function fromFullName( - BaseConnection $db, + string $dbPrefix, string $table, string $schema = '', string $database = '', string $alias = '' ): self { return new self( - $db->DBPrefix . $table, + $dbPrefix . $table, $table, $schema, $database, diff --git a/tests/system/Database/Builder/AliasTest.php b/tests/system/Database/Builder/AliasTest.php index 491bc282c509..a5e3dd0ad29e 100644 --- a/tests/system/Database/Builder/AliasTest.php +++ b/tests/system/Database/Builder/AliasTest.php @@ -44,7 +44,7 @@ public function testAlias(): void public function testTableName(): void { - $tableName = TableName::create($this->db, 'jobs', 'j'); + $tableName = TableName::create($this->db->DBPrefix, 'jobs', 'j'); $builder = $this->db->table($tableName); $expectedSQL = 'SELECT * FROM "jobs" "j"'; diff --git a/tests/system/Database/TableNameTest.php b/tests/system/Database/TableNameTest.php index 6d0e1967d81a..99f447879f5d 100644 --- a/tests/system/Database/TableNameTest.php +++ b/tests/system/Database/TableNameTest.php @@ -38,7 +38,7 @@ public function testInstantiate(): void { $table = 'table'; - $tableName = TableName::create($this->db, $table); + $tableName = TableName::create($this->db->DBPrefix, $table); $this->assertInstanceOf(TableName::class, $tableName); } @@ -47,7 +47,7 @@ public function testCreateAndTableName(): void { $table = 'table'; - $tableName = TableName::create($this->db, $table); + $tableName = TableName::create($this->db->DBPrefix, $table); $this->assertSame($table, $tableName->getTableName()); $this->assertSame('db_table', $tableName->getActualTableName()); @@ -57,7 +57,7 @@ public function testFromActualNameAndTableNameWithPrefix(): void { $actualTable = 'db_table'; - $tableName = TableName::fromActualName($this->db, $actualTable); + $tableName = TableName::fromActualName($this->db->DBPrefix, $actualTable); $this->assertSame('table', $tableName->getTableName()); $this->assertSame($actualTable, $tableName->getActualTableName()); @@ -67,7 +67,7 @@ public function testFromActualNameAndTableNameWithoutPrefix(): void { $actualTable = 'table'; - $tableName = TableName::fromActualName($this->db, $actualTable); + $tableName = TableName::fromActualName($this->db->DBPrefix, $actualTable); $this->assertSame('', $tableName->getTableName()); $this->assertSame($actualTable, $tableName->getActualTableName()); @@ -78,7 +78,7 @@ public function testGetAlias(): void $table = 'table'; $alias = 't'; - $tableName = TableName::create($this->db, $table, $alias); + $tableName = TableName::create($this->db->DBPrefix, $table, $alias); $this->assertSame($alias, $tableName->getAlias()); } @@ -89,7 +89,7 @@ public function testGetSchema(): void $schema = 'dbo'; $database = 'test'; - $tableName = TableName::fromFullName($this->db, $table, $schema, $database); + $tableName = TableName::fromFullName($this->db->DBPrefix, $table, $schema, $database); $this->assertSame($schema, $tableName->getSchema()); } @@ -100,7 +100,7 @@ public function testGetDatabase(): void $schema = 'dbo'; $database = 'test'; - $tableName = TableName::fromFullName($this->db, $table, $schema, $database); + $tableName = TableName::fromFullName($this->db->DBPrefix, $table, $schema, $database); $this->assertSame($database, $tableName->getDatabase()); }