@@ -48,30 +48,31 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
48
48
{
49
49
// @codingStandardsIgnoreEnd
50
50
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 ' ;
54
54
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 ' ;
61
62
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 ;
65
66
66
67
/**
67
68
* MEMORY engine type for MySQL tables
68
69
*/
69
- const ENGINE_MEMORY = 'MEMORY ' ;
70
+ public const ENGINE_MEMORY = 'MEMORY ' ;
70
71
71
72
/**
72
73
* Maximum number of connection retries
73
74
*/
74
- const MAX_CONNECTION_RETRIES = 10 ;
75
+ public const MAX_CONNECTION_RETRIES = 10 ;
75
76
76
77
/**
77
78
* Default class name for a DB statement.
@@ -1631,7 +1632,13 @@ public function resetDdlCache($tableName = null, $schemaName = null)
1631
1632
} else {
1632
1633
$ cacheKey = $ this ->_getTableName ($ tableName , $ schemaName );
1633
1634
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
+ ];
1635
1642
foreach ($ ddlTypes as $ ddlType ) {
1636
1643
unset($ this ->_ddlCache [$ ddlType ][$ cacheKey ]);
1637
1644
}
@@ -2658,7 +2665,30 @@ public function truncateTable($tableName, $schemaName = null)
2658
2665
*/
2659
2666
public function isTableExists ($ tableName , $ schemaName = null )
2660
2667
{
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 ;
2662
2692
}
2663
2693
2664
2694
/**
0 commit comments