Skip to content

Commit 3a6007f

Browse files
ENGCOM-7622: Rewrote Magento\Framework\DB\Adapter\Pdo\Mysql->isTableExists #28516
2 parents 5192283 + 6d89270 commit 3a6007f

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

dev/tests/integration/testsuite/Magento/MediaStorage/Console/Command/ImageResizeCommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function testExecuteWithZeroByteImage()
116116
*
117117
* @magentoDataFixture Magento/MediaStorage/_files/database_mode.php
118118
* @magentoDataFixture Magento/MediaStorage/_files/product_with_missed_image.php
119+
* @magentoDbIsolation disabled
119120
*/
120121
public function testDatabaseStorageMissingFile()
121122
{

dev/tests/integration/testsuite/Magento/MediaStorage/Helper/File/Storage/DatabaseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function setUp(): void
5252
/**
5353
* test for \Magento\MediaStorage\Model\File\Storage\Database::deleteFolder()
5454
*
55-
* @magentoDbIsolation enabled
55+
* @magentoDbIsolation disabled
5656
* @magentoDataFixture Magento/MediaStorage/_files/database_mode.php
5757
* @magentoConfigFixture current_store system/media_storage_configuration/media_storage 1
5858
* @magentoConfigFixture current_store system/media_storage_configuration/media_database default_setup

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,31 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
4848
{
4949
// @codingStandardsIgnoreEnd
5050

51-
const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
52-
const DATETIME_FORMAT = 'Y-m-d H:i:s';
53-
const DATE_FORMAT = 'Y-m-d';
51+
public const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
52+
public const DATETIME_FORMAT = 'Y-m-d H:i:s';
53+
public const DATE_FORMAT = 'Y-m-d';
5454

55-
const DDL_DESCRIBE = 1;
56-
const DDL_CREATE = 2;
57-
const DDL_INDEX = 3;
58-
const DDL_FOREIGN_KEY = 4;
59-
const DDL_CACHE_PREFIX = 'DB_PDO_MYSQL_DDL';
60-
const DDL_CACHE_TAG = 'DB_PDO_MYSQL_DDL';
55+
public const DDL_DESCRIBE = 1;
56+
public const DDL_CREATE = 2;
57+
public const DDL_INDEX = 3;
58+
public const DDL_FOREIGN_KEY = 4;
59+
public const DDL_EXISTS = 5;
60+
public const DDL_CACHE_PREFIX = 'DB_PDO_MYSQL_DDL';
61+
public const DDL_CACHE_TAG = 'DB_PDO_MYSQL_DDL';
6162

62-
const LENGTH_TABLE_NAME = 64;
63-
const LENGTH_INDEX_NAME = 64;
64-
const LENGTH_FOREIGN_NAME = 64;
63+
public const LENGTH_TABLE_NAME = 64;
64+
public const LENGTH_INDEX_NAME = 64;
65+
public const LENGTH_FOREIGN_NAME = 64;
6566

6667
/**
6768
* MEMORY engine type for MySQL tables
6869
*/
69-
const ENGINE_MEMORY = 'MEMORY';
70+
public const ENGINE_MEMORY = 'MEMORY';
7071

7172
/**
7273
* Maximum number of connection retries
7374
*/
74-
const MAX_CONNECTION_RETRIES = 10;
75+
public const MAX_CONNECTION_RETRIES = 10;
7576

7677
/**
7778
* Default class name for a DB statement.
@@ -1631,7 +1632,13 @@ public function resetDdlCache($tableName = null, $schemaName = null)
16311632
} else {
16321633
$cacheKey = $this->_getTableName($tableName, $schemaName);
16331634

1634-
$ddlTypes = [self::DDL_DESCRIBE, self::DDL_CREATE, self::DDL_INDEX, self::DDL_FOREIGN_KEY];
1635+
$ddlTypes = [
1636+
self::DDL_DESCRIBE,
1637+
self::DDL_CREATE,
1638+
self::DDL_INDEX,
1639+
self::DDL_FOREIGN_KEY,
1640+
self::DDL_EXISTS
1641+
];
16351642
foreach ($ddlTypes as $ddlType) {
16361643
unset($this->_ddlCache[$ddlType][$cacheKey]);
16371644
}
@@ -2658,7 +2665,30 @@ public function truncateTable($tableName, $schemaName = null)
26582665
*/
26592666
public function isTableExists($tableName, $schemaName = null)
26602667
{
2661-
return $this->showTableStatus($tableName, $schemaName) !== false;
2668+
$cacheKey = $this->_getTableName($tableName, $schemaName);
2669+
2670+
$ddl = $this->loadDdlCache($cacheKey, self::DDL_EXISTS);
2671+
if ($ddl !== false) {
2672+
return true;
2673+
}
2674+
2675+
$fromDbName = 'DATABASE()';
2676+
if ($schemaName !== null) {
2677+
$fromDbName = $this->quote($schemaName);
2678+
}
2679+
2680+
$sql = sprintf(
2681+
'SELECT COUNT(1) AS tbl_exists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = %s AND TABLE_SCHEMA = %s',
2682+
$this->quote($tableName),
2683+
$fromDbName
2684+
);
2685+
$ddl = $this->rawFetchRow($sql, 'tbl_exists');
2686+
if ($ddl) {
2687+
$this->saveDdlCache($cacheKey, self::DDL_EXISTS, $ddl);
2688+
return true;
2689+
}
2690+
2691+
return false;
26622692
}
26632693

26642694
/**

0 commit comments

Comments
 (0)