@@ -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