diff --git a/libraries/Table.class.php b/libraries/Table.class.php
index b811cfedf..57bcd9a05 100644
--- a/libraries/Table.class.php
+++ b/libraries/Table.class.php
@@ -243,13 +243,32 @@ class PMA_Table
// from the result set are NULL except Name and Comment.
// MySQL from 5.0.0 to 5.0.12 returns 'view',
// from 5.0.13 returns 'VIEW'.
- if (! isset(PMA_Table::$cache[$db][$table]['Comment'])) {
- PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'');
- }
- $comment = strtoupper(PMA_Table::$cache[$db][$table]['Comment']);
// use substr() because the comment might contain something like:
// (VIEW 'BASE2.VTEST' REFERENCES INVALID TABLE(S) OR COLUMN(S) OR FUNCTION)
- return (substr($comment, 0, 4) == 'VIEW');
+ $comment = strtoupper(PMA_Table::sGetStatusInfo($db, $table, 'Comment'));
+ return substr($comment, 0, 4) == 'VIEW';
+ }
+
+ static public function sGetToolTip($db, $table)
+ {
+ return PMA_Table::sGetStatusInfo($db, $table, 'Comment')
+ . ' (' . PMA_Table::countRecords($db, $table, true) . ')';
+ }
+
+ static public function sGetStatusInfo($db, $table, $info = null)
+ {
+ if (! isset(PMA_Table::$cache[$db][$table])) {
+ PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'');
+ }
+
+ if (null === $info) {
+ return PMA_Table::$cache[$db][$table];
+ }
+
+ if (! isset(PMA_Table::$cache[$db][$table][$info])) {
+ PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . $table . '\'');
+ }
+ return PMA_Table::$cache[$db][$table][$info];
}
/**
@@ -384,50 +403,54 @@ class PMA_Table
static public function countRecords($db, $table, $ret = false,
$force_exact = false, $is_view = null)
{
- $row_count = false;
-
- if (null === $is_view) {
- $is_view = PMA_Table::isView($db, $table);
- }
-
- if (! $force_exact) {
- if (! isset(PMA_Table::$cache[$db][$table]['Rows']) && ! $is_view) {
- PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\'');
+ if (isset(PMA_Table::$cache[$db][$table]['ExactRows'])) {
+ $row_count = PMA_Table::$cache[$db][$table]['ExactRows'];
+ } else {
+ $row_count = false;
+
+ if (null === $is_view) {
+ $is_view = PMA_Table::isView($db, $table);
}
- $row_count = PMA_Table::$cache[$db][$table]['Rows'];
- }
-
- // for a VIEW, $row_count is always false at this point
- if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
- if (! $is_view) {
- $row_count = PMA_DBI_fetch_value(
- 'SELECT COUNT(*) FROM ' . PMA_backquote($db) . '.'
- . PMA_backquote($table));
- } else {
- // For complex views, even trying to get a partial record
- // count could bring down a server, so we offer an
- // alternative: setting MaxExactCountViews to 0 will bypass
- // completely the record counting for views
-
- if ($GLOBALS['cfg']['MaxExactCountViews'] == 0) {
- $row_count = 0;
+
+ if (! $force_exact) {
+ if (! isset(PMA_Table::$cache[$db][$table]['Rows']) && ! $is_view) {
+ PMA_Table::$cache[$db][$table] = PMA_DBI_fetch_single_row('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\'');
+ }
+ $row_count = PMA_Table::$cache[$db][$table]['Rows'];
+ }
+
+ // for a VIEW, $row_count is always false at this point
+ if (false === $row_count || $row_count < $GLOBALS['cfg']['MaxExactCount']) {
+ if (! $is_view) {
+ $row_count = PMA_DBI_fetch_value(
+ 'SELECT COUNT(*) FROM ' . PMA_backquote($db) . '.'
+ . PMA_backquote($table));
} else {
- // Counting all rows of a VIEW could be too long, so use
- // a LIMIT clause.
- // Use try_query because it can fail (a VIEW is based on
- // a table that no longer exists)
- $result = PMA_DBI_try_query(
- 'SELECT 1 FROM ' . PMA_backquote($db) . '.'
- . PMA_backquote($table) . ' LIMIT '
- . $GLOBALS['cfg']['MaxExactCountViews'],
- null, PMA_DBI_QUERY_STORE);
- if (!PMA_DBI_getError()) {
- $row_count = PMA_DBI_num_rows($result);
- PMA_DBI_free_result($result);
+ // For complex views, even trying to get a partial record
+ // count could bring down a server, so we offer an
+ // alternative: setting MaxExactCountViews to 0 will bypass
+ // completely the record counting for views
+
+ if ($GLOBALS['cfg']['MaxExactCountViews'] == 0) {
+ $row_count = 0;
+ } else {
+ // Counting all rows of a VIEW could be too long, so use
+ // a LIMIT clause.
+ // Use try_query because it can fail (a VIEW is based on
+ // a table that no longer exists)
+ $result = PMA_DBI_try_query(
+ 'SELECT 1 FROM ' . PMA_backquote($db) . '.'
+ . PMA_backquote($table) . ' LIMIT '
+ . $GLOBALS['cfg']['MaxExactCountViews'],
+ null, PMA_DBI_QUERY_STORE);
+ if (!PMA_DBI_getError()) {
+ $row_count = PMA_DBI_num_rows($result);
+ PMA_DBI_free_result($result);
+ }
}
}
+ PMA_Table::$cache[$db][$table]['ExactRows'] = $row_count;
}
- PMA_Table::$cache[$db][$table]['Rows'] = $row_count;
}
if ($ret) {
diff --git a/libraries/common.lib.php b/libraries/common.lib.php
index ce31f67f6..2081d3497 100644
--- a/libraries/common.lib.php
+++ b/libraries/common.lib.php
@@ -960,22 +960,14 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice')
// Corrects the tooltip text via JS if required
// @todo this is REALLY the wrong place to do this - very unexpected here
if (strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
- $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
- if ($result) {
- $tbl_status = PMA_DBI_fetch_assoc($result);
- $tooltip = (empty($tbl_status['Comment']))
- ? ''
- : $tbl_status['Comment'] . ' ';
- $tooltip .= '(' . PMA_formatNumber($tbl_status['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')';
- PMA_DBI_free_result($result);
- $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
- echo "\n";
- echo '' . "\n";
- } // end if
+ $tooltip = PMA_Table::sGetToolTip($GLOBALS['db'], $GLOBALS['table']);
+ $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
+ echo "\n";
+ echo '' . "\n";
} // end if ... elseif
// Checks if the table needs to be repaired after a TRUNCATE query.
@@ -983,14 +975,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice')
// @todo this is REALLY the wrong place to do this - very unexpected here
if (strlen($GLOBALS['table'])
&& $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
- if (!isset($tbl_status)) {
- $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
- if ($result) {
- $tbl_status = PMA_DBI_fetch_assoc($result);
- PMA_DBI_free_result($result);
- }
- }
- if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
+ if (PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Index_length') > 1024) {
PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
}
}
diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php
index 8486cc7d7..3e9c92085 100644
--- a/libraries/db_table_exists.lib.php
+++ b/libraries/db_table_exists.lib.php
@@ -10,6 +10,8 @@
/**
*
*/
+require_once './libraries/Table.class.php';
+
if (empty($is_db)) {
if (strlen($db)) {
$is_db = @PMA_DBI_select_db($db);
@@ -40,12 +42,17 @@ if (empty($is_db)) {
if (empty($is_table) && !defined('PMA_SUBMIT_MULT')) {
// Not a valid table name -> back to the db_sql.php
+
if (strlen($table)) {
- $_result = PMA_DBI_try_query(
- 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
- null, PMA_DBI_QUERY_STORE);
- $is_table = @PMA_DBI_num_rows($_result);
- PMA_DBI_free_result($_result);
+ $is_table = isset(PMA_Table::$cache[$db][$table]);
+
+ if (! $is_table) {
+ $_result = PMA_DBI_try_query(
+ 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
+ null, PMA_DBI_QUERY_STORE);
+ $is_table = @PMA_DBI_num_rows($_result);
+ PMA_DBI_free_result($_result);
+ }
} else {
$is_table = false;
}
diff --git a/libraries/tbl_info.inc.php b/libraries/tbl_info.inc.php
index 73f076c62..dad487033 100644
--- a/libraries/tbl_info.inc.php
+++ b/libraries/tbl_info.inc.php
@@ -36,30 +36,21 @@ global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
// otherwise error #1046, no database selected
PMA_DBI_select_db($GLOBALS['db']);
-$table_info_result = PMA_DBI_query(
- 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
- null, PMA_DBI_QUERY_STORE);
+$showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table']);
// need this test because when we are creating a table, we get 0 rows
// from the SHOW TABLE query
// and we don't want to mess up the $tbl_type coming from the form
-if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
- $showtable = PMA_DBI_fetch_assoc($table_info_result);
- PMA_DBI_free_result($table_info_result);
- unset($table_info_result);
-
- if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
- $showtable['Type'] =& $showtable['Engine'];
- }
+if ($showtable) {
if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
$tbl_is_view = true;
$tbl_type = $GLOBALS['strView'];
$show_comment = null;
} else {
$tbl_is_view = false;
- $tbl_type = isset($showtable['Type'])
- ? strtoupper($showtable['Type'])
+ $tbl_type = isset($showtable['Engine'])
+ ? strtoupper($showtable['Engine'])
: '';
// a new comment could be coming from tbl_operations.php
// and we want to show it in the header