From 9ebe71c120b23961ff8d2087efd955d9cec6661d Mon Sep 17 00:00:00 2001 From: sclubricants Date: Tue, 9 Aug 2022 14:55:15 -0700 Subject: [PATCH 1/6] Add $cached param to BaseConnection::tableExists() --- system/Database/BaseConnection.php | 41 ++++++++++++++-- system/Database/Forge.php | 2 +- system/Database/MySQLi/Connection.php | 8 ++- system/Database/OCI8/Connection.php | 8 ++- system/Database/Postgre/Connection.php | 8 ++- system/Database/SQLSRV/Connection.php | 8 ++- system/Database/SQLite3/Connection.php | 10 +++- system/Test/Mock/MockConnection.php | 4 +- .../system/Database/Forge/CreateTableTest.php | 20 -------- tests/system/Database/Live/ForgeTest.php | 49 +++++++++++++++++++ 10 files changed, 128 insertions(+), 30 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 413c0a4726ee..c43bf5c2f72a 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1406,9 +1406,42 @@ public function listTables(bool $constrainByPrefix = false) /** * Determine if a particular table exists */ - public function tableExists(string $tableName): bool + public function tableExists(string $tableName, bool $cached = true): bool { - return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true); + if ($cached === true) { + return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true); + } + + if (false === ($sql = $this->_listTables(false, $tableName))) { + if ($this->DBDebug) { + throw new DatabaseException('This feature is not available for the database you are using.'); + } + + return false; + } + + $result = $this->query($sql)->getResultArray() !== []; + + // if cache has been built already + if (! empty($this->dataCache['table_names'])) { + $key = array_search( + strtolower($tableName), + array_map('strtolower', $this->dataCache['table_names']), + true + ); + + // remove from cache + if ($key !== false) { + unset($this->dataCache['table_names'][$key]); + } + + // if exists add back to cache (if cache has been built already) + if ($result) { + $this->dataCache['table_names'][] = strtolower($tableName); + } + } + + return $result; } /** @@ -1575,9 +1608,11 @@ abstract public function insertID(); /** * Generates the SQL for listing tables in a platform-dependent manner. * + * @param string $tableName If $tableName is provided will return only this table if exists. + * * @return false|string */ - abstract protected function _listTables(bool $constrainByPrefix = false); + abstract protected function _listTables(bool $constrainByPrefix = false, string $tableName = ''); /** * Generates a platform-specific query string so that the column names can be fetched. diff --git a/system/Database/Forge.php b/system/Database/Forge.php index d46dfdfde498..458e60b22442 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -498,7 +498,7 @@ public function createTable(string $table, bool $ifNotExists = false, array $att } // If table exists lets stop here - if ($ifNotExists === true && $this->db->tableExists($table)) { + if ($ifNotExists === true && $this->db->tableExists($table, false)) { $this->reset(); return true; diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index e4fd5b3f5463..9df7df8b0511 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -368,11 +368,17 @@ public function escapeLikeStringDirect($str) /** * Generates the SQL for listing tables in a platform-dependent manner. * Uses escapeLikeStringDirect(). + * + * @param string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string { $sql = 'SHOW TABLES FROM ' . $this->escapeIdentifiers($this->database); + if (! empty($tableName)) { + return $sql . ' LIKE ' . $this->escape($tableName); + } + if ($prefixLimit !== false && $this->DBPrefix !== '') { return $sql . " LIKE '" . $this->escapeLikeStringDirect($this->DBPrefix) . "%'"; } diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index b84111fb0aa8..c7c608ff8cca 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -242,11 +242,17 @@ public function affectedRows(): int /** * Generates the SQL for listing tables in a platform-dependent manner. + * + * @param string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string { $sql = 'SELECT "TABLE_NAME" FROM "USER_TABLES"'; + if (! empty($tableName)) { + return $sql . ' WHERE "TABLE_NAME" LIKE ' . $this->escape($tableName); + } + if ($prefixLimit !== false && $this->DBPrefix !== '') { return $sql . ' WHERE "TABLE_NAME" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . "%' " . sprintf($this->likeEscapeStr, $this->likeEscapeChar); diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 7b58bdb237d8..6fc278f106ad 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -204,11 +204,17 @@ protected function _escapeString(string $str): string /** * Generates the SQL for listing tables in a platform-dependent manner. + * + * @param string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string { $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'' . $this->schema . "'"; + if (! empty($tableName)) { + return $sql . ' AND "table_name" LIKE ' . $this->escape($tableName); + } + if ($prefixLimit !== false && $this->DBPrefix !== '') { return $sql . ' AND "table_name" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . "%' " diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index f180ca4f6b3b..e07a719a8223 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -183,14 +183,20 @@ public function insertID(): int /** * Generates the SQL for listing tables in a platform-dependent manner. + * + * @param string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string { $sql = 'SELECT [TABLE_NAME] AS "name"' . ' FROM [INFORMATION_SCHEMA].[TABLES] ' . ' WHERE ' . " [TABLE_SCHEMA] = '" . $this->schema . "' "; + if (! empty($tableName)) { + return $sql .= ' AND [TABLE_NAME] LIKE ' . $this->escape($tableName); + } + if ($prefixLimit === true && $this->DBPrefix !== '') { $sql .= " AND [TABLE_NAME] LIKE '" . $this->escapeLikeString($this->DBPrefix) . "%' " . sprintf($this->likeEscapeStr, $this->likeEscapeChar); diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 1085b30b461e..62a6105c7245 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -160,9 +160,17 @@ protected function _escapeString(string $str): string /** * Generates the SQL for listing tables in a platform-dependent manner. + * + * @param string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string { + if (! empty($tableName)) { + return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' + . ' AND "NAME" NOT LIKE \'sqlite!_%\' ESCAPE \'!\'' + . ' AND "NAME" LIKE ' . $this->escape($tableName); + } + return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' . ' AND "NAME" NOT LIKE \'sqlite!_%\' ESCAPE \'!\'' . (($prefixLimit !== false && $this->DBPrefix !== '') diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 2d95b496aab8..ade51680120b 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -179,8 +179,10 @@ public function insertID(): int /** * Generates the SQL for listing tables in a platform-dependent manner. + * + * @param string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $constrainByPrefix = false): string + protected function _listTables(bool $constrainByPrefix = false, string $tableName = ''): string { return ''; } diff --git a/tests/system/Database/Forge/CreateTableTest.php b/tests/system/Database/Forge/CreateTableTest.php index 4a9c92bd6f27..a390e03c3cd7 100644 --- a/tests/system/Database/Forge/CreateTableTest.php +++ b/tests/system/Database/Forge/CreateTableTest.php @@ -21,26 +21,6 @@ */ final class CreateTableTest extends CIUnitTestCase { - public function testCreateTableWithExists() - { - $dbMock = $this->getMockBuilder(MockConnection::class) - ->setConstructorArgs([[]]) - ->onlyMethods(['listTables']) - ->getMock(); - $dbMock - ->method('listTables') - ->willReturn(['foo']); - - $forge = new class ($dbMock) extends Forge { - protected $createTableIfStr = false; - }; - - $forge->addField('id'); - $actual = $forge->createTable('foo', true); - - $this->assertTrue($actual); - } - public function testCreateTableWithDefaultRawSql() { $sql = <<<'SQL' diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 2122afb36a45..11fb663787c9 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -155,6 +155,55 @@ public function testCreateTable() $this->forge->dropTable('forge_test_table', true); } + public function testCreateTableWithExists() + { + // create table so that it exists in database + $this->forge->addField([ + 'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true], + 'name' => ['type' => 'VARCHAR', 'constraint' => 80], + ])->addKey('id', true)->createTable('test_exists', true); + + // table exists in cache + $this->assertTrue($this->forge->getConnection()->tableExists('db_test_exists', true)); + + // table exists without cached results + $this->assertTrue($this->forge->getConnection()->tableExists('db_test_exists', false)); + + // try creating table when table exists + $result = $this->forge->addField([ + 'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true], + 'name' => ['type' => 'VARCHAR', 'constraint' => 80], + ])->addKey('id', true)->createTable('test_exists', true); + + $this->assertTrue($result); + + // Delete table outside of forge. This should leave table in cache as existing. + $this->forge->getConnection()->query('DROP TABLE ' . $this->forge->getConnection()->protectIdentifiers('db_test_exists', true, null, false)); + + // table stil exists in cache + $this->assertTrue($this->forge->getConnection()->tableExists('db_test_exists', true)); + + // table does not exist without cached results - this will update the cache + $this->assertFalse($this->forge->getConnection()->tableExists('db_test_exists', false)); + + // the call above should update the cache - table should not exist in cache anymore + $this->assertFalse($this->forge->getConnection()->tableExists('db_test_exists', true)); + + // try creating table when table does not exist but still in cache + $result = $this->forge->addField([ + 'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true], + 'name' => ['type' => 'VARCHAR', 'constraint' => 80], + ])->addKey('id', true)->createTable('test_exists', true); + + $this->assertTrue($result); + + // check that the table does now exist without cached results + $this->assertTrue($this->forge->getConnection()->tableExists('db_test_exists', false)); + + // drop table so that it doesn't mess up other tests + $this->forge->dropTable('test_exists'); + } + public function testCreateTableApplyBigInt() { $this->forge->dropTable('forge_test_table', true); From 79fe8370932de4bf6f82499788969e0b7904a5d1 Mon Sep 17 00:00:00 2001 From: sclubricants Date: Wed, 10 Aug 2022 15:01:25 -0700 Subject: [PATCH 2/6] change reset cache --- system/Database/BaseConnection.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index c43bf5c2f72a..0f2967bb4fb4 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1420,7 +1420,7 @@ public function tableExists(string $tableName, bool $cached = true): bool return false; } - $result = $this->query($sql)->getResultArray() !== []; + $tableExists = $this->query($sql)->getResultArray() !== []; // if cache has been built already if (! empty($this->dataCache['table_names'])) { @@ -1430,18 +1430,13 @@ public function tableExists(string $tableName, bool $cached = true): bool true ); - // remove from cache - if ($key !== false) { - unset($this->dataCache['table_names'][$key]); - } - - // if exists add back to cache (if cache has been built already) - if ($result) { - $this->dataCache['table_names'][] = strtolower($tableName); + // table doesn't exist but still in cache - lets reset cache, it can be rebuilt later + if ($key !== false && ! $tableExists) { + $this->resetDataCache(); } } - return $result; + return $tableExists; } /** From 843ff52fefe0dc37666a0e191353419aee4d29a0 Mon Sep 17 00:00:00 2001 From: sclubricants Date: Wed, 10 Aug 2022 15:23:24 -0700 Subject: [PATCH 3/6] fix reset cache --- system/Database/BaseConnection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 0f2967bb4fb4..a15d3bc15f7e 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1431,7 +1431,8 @@ public function tableExists(string $tableName, bool $cached = true): bool ); // table doesn't exist but still in cache - lets reset cache, it can be rebuilt later - if ($key !== false && ! $tableExists) { + // OR if table does exist but is not found in cache + if (($key !== false && ! $tableExists) || ($key === false && $tableExists)) { $this->resetDataCache(); } } From ec4020769c7280a48781eb93c8a4375f38b4511b Mon Sep 17 00:00:00 2001 From: sclubricants Date: Thu, 11 Aug 2022 11:33:22 -0700 Subject: [PATCH 4/6] fix $tableName = null --- system/Database/BaseConnection.php | 4 ++-- system/Database/MySQLi/Connection.php | 6 +++--- system/Database/OCI8/Connection.php | 6 +++--- system/Database/Postgre/Connection.php | 6 +++--- system/Database/SQLSRV/Connection.php | 6 +++--- system/Database/SQLite3/Connection.php | 6 +++--- system/Test/Mock/MockConnection.php | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index a15d3bc15f7e..ee0890bfcb6c 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1604,11 +1604,11 @@ abstract public function insertID(); /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. * * @return false|string */ - abstract protected function _listTables(bool $constrainByPrefix = false, string $tableName = ''); + abstract protected function _listTables(bool $constrainByPrefix = false, ?string $tableName = null); /** * Generates a platform-specific query string so that the column names can be fetched. diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 9df7df8b0511..3df3cb9a054a 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -369,13 +369,13 @@ public function escapeLikeStringDirect($str) * Generates the SQL for listing tables in a platform-dependent manner. * Uses escapeLikeStringDirect(). * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string + protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SHOW TABLES FROM ' . $this->escapeIdentifiers($this->database); - if (! empty($tableName)) { + if ($tableName !== null) { return $sql . ' LIKE ' . $this->escape($tableName); } diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index c7c608ff8cca..79ae4f182bf0 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -243,13 +243,13 @@ public function affectedRows(): int /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string + protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SELECT "TABLE_NAME" FROM "USER_TABLES"'; - if (! empty($tableName)) { + if ($tableName !== null) { return $sql . ' WHERE "TABLE_NAME" LIKE ' . $this->escape($tableName); } diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 6fc278f106ad..36d3a7804568 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -205,13 +205,13 @@ protected function _escapeString(string $str): string /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string + protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'' . $this->schema . "'"; - if (! empty($tableName)) { + if ($tableName !== null) { return $sql . ' AND "table_name" LIKE ' . $this->escape($tableName); } diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index e07a719a8223..0e1c14647d2e 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -184,16 +184,16 @@ public function insertID(): int /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string + protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SELECT [TABLE_NAME] AS "name"' . ' FROM [INFORMATION_SCHEMA].[TABLES] ' . ' WHERE ' . " [TABLE_SCHEMA] = '" . $this->schema . "' "; - if (! empty($tableName)) { + if ($tableName !== null) { return $sql .= ' AND [TABLE_NAME] LIKE ' . $this->escape($tableName); } diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 62a6105c7245..bcdaeabefe22 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -161,11 +161,11 @@ protected function _escapeString(string $str): string /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $prefixLimit = false, string $tableName = ''): string + protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { - if (! empty($tableName)) { + if ($tableName !== null) { return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' . ' AND "NAME" NOT LIKE \'sqlite!_%\' ESCAPE \'!\'' . ' AND "NAME" LIKE ' . $this->escape($tableName); diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index ade51680120b..08cc3789617a 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -180,9 +180,9 @@ public function insertID(): int /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param string $tableName If $tableName is provided will return only this table if exists. + * @param null|string $tableName If $tableName is provided will return only this table if exists. */ - protected function _listTables(bool $constrainByPrefix = false, string $tableName = ''): string + protected function _listTables(bool $constrainByPrefix = false, ?string $tableName = null): string { return ''; } From 8077f2f565a2b5bc5266e1b4a36a7b058e4effea Mon Sep 17 00:00:00 2001 From: sclubricants Date: Thu, 11 Aug 2022 11:39:01 -0700 Subject: [PATCH 5/6] fix --- system/Database/BaseConnection.php | 2 +- system/Database/MySQLi/Connection.php | 2 +- system/Database/OCI8/Connection.php | 2 +- system/Database/Postgre/Connection.php | 2 +- system/Database/SQLSRV/Connection.php | 2 +- system/Database/SQLite3/Connection.php | 2 +- system/Test/Mock/MockConnection.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index ee0890bfcb6c..9da237d37192 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1604,7 +1604,7 @@ abstract public function insertID(); /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. * * @return false|string */ diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 3df3cb9a054a..5488852318c5 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -369,7 +369,7 @@ public function escapeLikeStringDirect($str) * Generates the SQL for listing tables in a platform-dependent manner. * Uses escapeLikeStringDirect(). * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 79ae4f182bf0..081a2777a12e 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -243,7 +243,7 @@ public function affectedRows(): int /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 36d3a7804568..f7efdb9b4f36 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -205,7 +205,7 @@ protected function _escapeString(string $str): string /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 0e1c14647d2e..e4d0005c80fe 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -184,7 +184,7 @@ public function insertID(): int /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index bcdaeabefe22..4d7ae0ee45e8 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -161,7 +161,7 @@ protected function _escapeString(string $str): string /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 08cc3789617a..f515550569a9 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -180,7 +180,7 @@ public function insertID(): int /** * Generates the SQL for listing tables in a platform-dependent manner. * - * @param null|string $tableName If $tableName is provided will return only this table if exists. + * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $constrainByPrefix = false, ?string $tableName = null): string { From b2f2f610febcb9e8e6260da202bc4e47ea2a030d Mon Sep 17 00:00:00 2001 From: sclubricants Date: Sun, 14 Aug 2022 12:53:58 -0700 Subject: [PATCH 6/6] Review Fixes --- system/Database/BaseConnection.php | 2 ++ user_guide_src/source/changelogs/v4.2.5.rst | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 9da237d37192..7998c8cf6df3 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1405,6 +1405,8 @@ public function listTables(bool $constrainByPrefix = false) /** * Determine if a particular table exists + * + * @param bool $cached Whether to use data cache */ public function tableExists(string $tableName, bool $cached = true): bool { diff --git a/user_guide_src/source/changelogs/v4.2.5.rst b/user_guide_src/source/changelogs/v4.2.5.rst index 51fbbb2611cb..a670705e4153 100644 --- a/user_guide_src/source/changelogs/v4.2.5.rst +++ b/user_guide_src/source/changelogs/v4.2.5.rst @@ -12,7 +12,8 @@ Release Date: Unreleased BREAKING ******** -none. +- The method signature of ``BaseConnection::tableExists()`` has been changed. A second optional parameter ``$cached`` was added. This directs whether to use cache data or not. Default is ``true``, use cache data. +- The abstract method signature of ``BaseBuilder::_listTables()`` has been changed. A second optional parameter ``$tableName`` was added. Providing a table name will generate SQL listing only that table. Enhancements ************