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