From ecb999e010986143bb1c715c932f3c94d676f72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:02:11 +0200 Subject: [PATCH 01/14] Remove some unused variables --- libraries/replication.inc.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index 58ed7c5acc..857f4dc8da 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -298,21 +298,14 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) { $src_db = $trg_db = $db; - $src_connection = PMA_DBI_select_db($src_db, $src_link); - $trg_connection = PMA_DBI_select_db($trg_db, $trg_link); - $src_tables = PMA_DBI_get_tables($src_db, $src_link); - $source_tables_num = sizeof($src_tables); $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link); - $target_tables_num = sizeof($trg_tables); /** * initializing arrays to save table names */ - $unmatched_num_src = 0; $source_tables_uncommon = array(); - $unmatched_num_trg = 0; $target_tables_uncommon = array(); $matching_tables = array(); $matching_tables_num = 0; @@ -367,6 +360,7 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) $source_indexes = array(); $target_indexes = array(); $add_indexes_array = array(); + $alter_indexes_array = array(); $remove_indexes_array = array(); $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment'); @@ -378,17 +372,11 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) $add_indexes_array, $alter_indexes_array,$remove_indexes_array, $counter); } - $matching_table_data_diff = array(); - $matching_table_structure_diff = array(); - $uncommon_table_structure_diff = array(); - $uncommon_table_data_diff = array(); - $uncommon_tables = $source_tables_uncommon; - /** * Generating Create Table query for all the non-matching tables present in Source but not in Target and populating tables. */ for ($q = 0; $q < sizeof($source_tables_uncommon); $q++) { - if (isset($uncommon_tables[$q])) { + if (isset($source_tables_uncommon[$q])) { PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, false); } if (isset($row_count[$q]) && $data) { From ab166dd8490cba11d172e8573f8b407fe4d776d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:06:46 +0200 Subject: [PATCH 02/14] Remove some unused vars --- libraries/schema/User_Schema.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/schema/User_Schema.class.php b/libraries/schema/User_Schema.class.php index 95d60e127b..53d29fec07 100644 --- a/libraries/schema/User_Schema.class.php +++ b/libraries/schema/User_Schema.class.php @@ -38,7 +38,7 @@ class PMA_User_Schema public function processUserChoice() { - global $action_choose,$db,$cfgRelation,$cfg; + global $action_choose, $db, $cfgRelation; if (isset($this->action)) { switch ($this->action) { @@ -207,7 +207,7 @@ class PMA_User_Schema */ public function showTableDashBoard() { - global $db,$cfgRelation,$table,$cfg,$with_field_names; + global $db, $cfgRelation, $table, $with_field_names; /* * We will need an array of all tables in this db */ @@ -479,7 +479,7 @@ class PMA_User_Schema */ private function _displayScratchboardTables($array_sh_page) { - global $with_field_names,$cfg,$db; + global $with_field_names, $db; ?>
@@ -505,12 +505,12 @@ class PMA_User_Schema $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n"; $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n"; + /* TODO: use PMA_DBI_get_columns */ $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($temp_sh_page['table_name']) . ' FROM ' . PMA_backquote($db); $fields_rs = PMA_DBI_query($local_query); unset($local_query); - $fields_cnt = PMA_DBI_num_rows($fields_rs); echo '
' . $temp_sh_page['table_name'] . ''; if (isset($with_field_names)) { From 88ef580bd5c575b8cdaa8dea2a3968cfd2504efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:09:12 +0200 Subject: [PATCH 03/14] Use PMA_DBI_get_columns instead of custom query --- libraries/schema/User_Schema.class.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libraries/schema/User_Schema.class.php b/libraries/schema/User_Schema.class.php index 53d29fec07..4ed00f2e18 100644 --- a/libraries/schema/User_Schema.class.php +++ b/libraries/schema/User_Schema.class.php @@ -505,22 +505,14 @@ class PMA_User_Schema $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n"; $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n"; - /* TODO: use PMA_DBI_get_columns */ - $local_query = 'SHOW FIELDS FROM ' - . PMA_backquote($temp_sh_page['table_name']) - . ' FROM ' . PMA_backquote($db); - $fields_rs = PMA_DBI_query($local_query); - unset($local_query); - echo '
' . $temp_sh_page['table_name'] . ''; if (isset($with_field_names)) { - while ($row = PMA_DBI_fetch_assoc($fields_rs)) { + $fields = PMA_DBI_get_columns($db, $temp_sh_page['table_name']) + foreach ($fields as $row) { echo '
' . htmlspecialchars($row['Field']) . "\n"; } } echo '
' . "\n"; - PMA_DBI_free_result($fields_rs); - unset($fields_rs); $i++; } ?> From dd046f10b338bbdd491526a12f3e6dd0a7c45dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:11:01 +0200 Subject: [PATCH 04/14] Fix typo --- libraries/schema/User_Schema.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/schema/User_Schema.class.php b/libraries/schema/User_Schema.class.php index 4ed00f2e18..36029587f5 100644 --- a/libraries/schema/User_Schema.class.php +++ b/libraries/schema/User_Schema.class.php @@ -507,7 +507,7 @@ class PMA_User_Schema echo '
' . $temp_sh_page['table_name'] . ''; if (isset($with_field_names)) { - $fields = PMA_DBI_get_columns($db, $temp_sh_page['table_name']) + $fields = PMA_DBI_get_columns($db, $temp_sh_page['table_name']); foreach ($fields as $row) { echo '
' . htmlspecialchars($row['Field']) . "\n"; } From f0babc56a34afaf2664328a332e871c0116468d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:11:06 +0200 Subject: [PATCH 05/14] Fix indentation --- libraries/schema/User_Schema.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/schema/User_Schema.class.php b/libraries/schema/User_Schema.class.php index 36029587f5..41a2b9e6fe 100644 --- a/libraries/schema/User_Schema.class.php +++ b/libraries/schema/User_Schema.class.php @@ -509,7 +509,7 @@ class PMA_User_Schema if (isset($with_field_names)) { $fields = PMA_DBI_get_columns($db, $temp_sh_page['table_name']); foreach ($fields as $row) { - echo '
' . htmlspecialchars($row['Field']) . "\n"; + echo '
' . htmlspecialchars($row['Field']) . "\n"; } } echo '
' . "\n"; From e350eaeae71dcacc946e5686a526576103f5f32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:13:21 +0200 Subject: [PATCH 06/14] Use PMA_DBI_get_columns instead of custom query --- db_search.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db_search.php b/db_search.php index c0f2c082af..6242a53d9b 100644 --- a/db_search.php +++ b/db_search.php @@ -128,8 +128,7 @@ if (isset($_REQUEST['submit_search'])) { $sqlstr_delete = 'DELETE'; // Fields to select - $tblfields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']), - null, 'Field'); + $tblfields = PMA_DBI_get_columns($GLOBALS['db'], $table); // Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table); @@ -148,8 +147,8 @@ if (isset($_REQUEST['submit_search'])) { $thefieldlikevalue = array(); foreach ($tblfields as $tblfield) { - if (! isset($field) || strlen($field) == 0 || $tblfield == $field) { - $thefieldlikevalue[] = 'CONVERT(' . PMA_backquote($tblfield) . ' USING utf8)' + if (! isset($field) || strlen($field) == 0 || $tblfield['Field'] == $field) { + $thefieldlikevalue[] = 'CONVERT(' . PMA_backquote($tblfield['Field']) . ' USING utf8)' . ' ' . $like_or_regex . ' ' . "'" . $automatic_wildcard . $search_word From f66f8b7074679180790312f87c874fecda86b86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:14:54 +0200 Subject: [PATCH 07/14] Use PMA_DBI_get_columns instead of custom query --- libraries/schema/Pdf_Relation_Schema.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/schema/Pdf_Relation_Schema.class.php b/libraries/schema/Pdf_Relation_Schema.class.php index e74c14d126..ed96efd053 100644 --- a/libraries/schema/Pdf_Relation_Schema.class.php +++ b/libraries/schema/Pdf_Relation_Schema.class.php @@ -923,8 +923,8 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema $pdf->SetX(10); $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']); // $pdf->Ln(1); - $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); - while ($row = PMA_DBI_fetch_assoc($result)) { + $fields = PMA_DBI_get_columns($GLOBALS['db'], $table); + foreach($fields as $row) { $pdf->SetX(20); $field_name = $row['Field']; $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink(); From 624fdc8b2a62971abe3dc14a46132bc61356a888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:16:17 +0200 Subject: [PATCH 08/14] Remove not used variable --- transformation_wrapper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/transformation_wrapper.php b/transformation_wrapper.php index 577a4353a0..1c5e16a3ec 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -27,7 +27,6 @@ require_once './libraries/db_table_exists.lib.php'; * Get the list of the fields of the current table */ PMA_DBI_select_db($db); -$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE); if (isset($where_clause)) { $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE); $row = PMA_DBI_fetch_assoc($result); From cea5d8791ef776dc87961ae4f69c393acdffe381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:17:21 +0200 Subject: [PATCH 09/14] Use PMA_DBI_get_columns instead of custom query --- tbl_change.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index 5329f159a1..bf0704a899 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -165,8 +165,7 @@ unset($show_create_table); * Get the list of the fields of the current table */ PMA_DBI_select_db($db); -$table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', - null, null, null, PMA_DBI_QUERY_STORE); +$table_fields = PMA_DBI_get_columns($db, $table); $rows = array(); if (isset($where_clause)) { // when in edit mode load all selected rows from table From 5209562dd3504c160f26f3d6466683fda7cdabfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:18:27 +0200 Subject: [PATCH 10/14] Use PMA_DBI_get_columns instead of custom query --- libraries/sql_query_form.lib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index 542cfc3306..beab95d80b 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -213,9 +213,7 @@ function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchonize and the table has not yet been created - $fields_list = PMA_DBI_fetch_result( - 'SHOW FULL COLUMNS FROM ' . PMA_backquote($db) - . '.' . PMA_backquote($GLOBALS['table'])); + $fields_list = PMA_DBI_get_columns($db, $GLOBALS['table'], true); $tmp_db_link = ' Date: Fri, 19 Aug 2011 09:20:23 +0200 Subject: [PATCH 11/14] Use PMA_DBI_get_columns instead of custom query --- libraries/tbl_select.lib.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index af97aa434e..57c520dfc5 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -59,12 +59,11 @@ function PMA_tbl_getFields($table,$db) { // Gets the list and number of fields - $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); - $fields_cnt = PMA_DBI_num_rows($result); + $fields = PMA_DBI_get_columns($db, $table, true); $fields_list = $fields_null = $fields_type = $fields_collation = array(); $geom_column_present = false; $geom_types = PMA_getGISDatatypes(); - while ($row = PMA_DBI_fetch_assoc($result)) { + foreach ($fields as $row) { $fields_list[] = $row['Field']; $type = $row['Type']; // check whether table contains geometric columns @@ -96,8 +95,6 @@ function PMA_tbl_getFields($table,$db) { ? $row['Collation'] : ''; } // end while - PMA_DBI_free_result($result); - unset($result, $type); return array($fields_list,$fields_type,$fields_collation,$fields_null, $geom_column_present); From 555aa5cfa2f40382068c9f23c12ecc3c7023c2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:31:43 +0200 Subject: [PATCH 12/14] Fix indentation --- server_status.php | 366 +++++++++++++++++++++++----------------------- 1 file changed, 185 insertions(+), 181 deletions(-) diff --git a/server_status.php b/server_status.php index 8d196adb85..ce4df7564e 100644 --- a/server_status.php +++ b/server_status.php @@ -31,161 +31,161 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { // real-time charting data if (isset($_REQUEST['chart_data'])) { switch($_REQUEST['type']) { - // Process and Connections realtime chart - case 'proc': - $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1); - $result = PMA_DBI_query('SHOW PROCESSLIST'); - $num_procs = PMA_DBI_num_rows($result); + // Process and Connections realtime chart + case 'proc': + $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1); + $result = PMA_DBI_query('SHOW PROCESSLIST'); + $num_procs = PMA_DBI_num_rows($result); - $ret = array( - 'x' => microtime(true)*1000, - 'y_proc' => $num_procs, - 'y_conn' => $c['Connections'] - ); + $ret = array( + 'x' => microtime(true)*1000, + 'y_proc' => $num_procs, + 'y_conn' => $c['Connections'] + ); - exit(json_encode($ret)); + exit(json_encode($ret)); - // Query realtime chart - case 'queries': - $queries = PMA_DBI_fetch_result( - "SHOW GLOBAL STATUS - WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions') - AND Value > 0'", 0, 1); - cleanDeprecated($queries); - // admin commands are not queries - unset($queries['Com_admin_commands']); - $questions = $queries['Questions']; - unset($queries['Questions']); + // Query realtime chart + case 'queries': + $queries = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS + WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions') + AND Value > 0'", 0, 1); + cleanDeprecated($queries); + // admin commands are not queries + unset($queries['Com_admin_commands']); + $questions = $queries['Questions']; + unset($queries['Questions']); - //$sum=array_sum($queries); - $ret = array( - 'x' => microtime(true)*1000, - 'y' => $questions, - 'pointInfo' => $queries - ); + //$sum=array_sum($queries); + $ret = array( + 'x' => microtime(true)*1000, + 'y' => $questions, + 'pointInfo' => $queries + ); - exit(json_encode($ret)); + exit(json_encode($ret)); - // Traffic realtime chart - case 'traffic': - $traffic = PMA_DBI_fetch_result( - "SHOW GLOBAL STATUS - WHERE Variable_name = 'Bytes_received' - OR Variable_name = 'Bytes_sent'", 0, 1); + // Traffic realtime chart + case 'traffic': + $traffic = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS + WHERE Variable_name = 'Bytes_received' + OR Variable_name = 'Bytes_sent'", 0, 1); - $ret = array( - 'x' => microtime(true)*1000, - 'y_sent' => $traffic['Bytes_sent'], - 'y_received' => $traffic['Bytes_received'] - ); + $ret = array( + 'x' => microtime(true)*1000, + 'y_sent' => $traffic['Bytes_sent'], + 'y_received' => $traffic['Bytes_received'] + ); - exit(json_encode($ret)); + exit(json_encode($ret)); - // Data for the monitor - case 'chartgrid': - $ret = json_decode($_REQUEST['requiredData'], true); - $statusVars = array(); - $serverVars = array(); - $sysinfo = $cpuload = $memory = 0; - $pName = ''; + // Data for the monitor + case 'chartgrid': + $ret = json_decode($_REQUEST['requiredData'], true); + $statusVars = array(); + $serverVars = array(); + $sysinfo = $cpuload = $memory = 0; + $pName = ''; - /* Accumulate all required variables and data */ - // For each chart - foreach ($ret as $chart_id => $chartNodes) { - // For each data series - foreach ($chartNodes as $node_id => $nodeDataPoints) { - // For each data point in the series (usually just 1) - foreach ($nodeDataPoints as $point_id => $dataPoint) { - $pName = $dataPoint['name']; + /* Accumulate all required variables and data */ + // For each chart + foreach ($ret as $chart_id => $chartNodes) { + // For each data series + foreach ($chartNodes as $node_id => $nodeDataPoints) { + // For each data point in the series (usually just 1) + foreach ($nodeDataPoints as $point_id => $dataPoint) { + $pName = $dataPoint['name']; - switch ($dataPoint['type']) { - /* We only collect the status and server variables here to - * read them all in one query, and only afterwards assign them. - * Also do some white list filtering on the names - */ - case 'servervar': - if (!preg_match('/[^a-zA-Z_]+/', $pName)) - $serverVars[] = $pName; - break; + switch ($dataPoint['type']) { + /* We only collect the status and server variables here to + * read them all in one query, and only afterwards assign them. + * Also do some white list filtering on the names + */ + case 'servervar': + if (!preg_match('/[^a-zA-Z_]+/', $pName)) + $serverVars[] = $pName; + break; - case 'statusvar': - if (!preg_match('/[^a-zA-Z_]+/', $pName)) - $statusVars[] = $pName; - break; + case 'statusvar': + if (!preg_match('/[^a-zA-Z_]+/', $pName)) + $statusVars[] = $pName; + break; - case 'proc': - $result = PMA_DBI_query('SHOW PROCESSLIST'); - $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result); - break; + case 'proc': + $result = PMA_DBI_query('SHOW PROCESSLIST'); + $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result); + break; - case 'cpu': - if (!$sysinfo) { - require_once('libraries/sysinfo.lib.php'); - $sysinfo = getSysInfo(); - } - if (!$cpuload) - $cpuload = $sysinfo->loadavg(); - - if (PHP_OS == 'Linux') { - $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle']; - $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy']; - } else - $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg']; - - break; - - case 'memory': - if (!$sysinfo) { - require_once('libraries/sysinfo.lib.php'); - $sysinfo = getSysInfo(); - } - if (!$memory) - $memory = $sysinfo->memory(); - - $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName]; - break; + case 'cpu': + if (!$sysinfo) { + require_once('libraries/sysinfo.lib.php'); + $sysinfo = getSysInfo(); } + if (!$cpuload) + $cpuload = $sysinfo->loadavg(); + + if (PHP_OS == 'Linux') { + $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle']; + $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy']; + } else + $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg']; + + break; + + case 'memory': + if (!$sysinfo) { + require_once('libraries/sysinfo.lib.php'); + $sysinfo = getSysInfo(); + } + if (!$memory) + $memory = $sysinfo->memory(); + + $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName]; + break; + } /* switch */ + } /* foreach */ + } /* foreach */ + } /* foreach */ + + // Retrieve all required status variables + if (count($statusVars)) { + $statusVarValues = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS + WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1); + } else { + $statusVarValues = array(); + } + + // Retrieve all required server variables + if (count($serverVars)) { + $serverVarValues = PMA_DBI_fetch_result( + "SHOW GLOBAL VARIABLES + WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1); + } else { + $serverVarValues = array(); + } + + // ...and now assign them + foreach ($ret as $chart_id => $chartNodes) { + foreach ($chartNodes as $node_id => $nodeDataPoints) { + foreach ($nodeDataPoints as $point_id => $dataPoint) { + switch($dataPoint['type']) { + case 'statusvar': + $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']]; + break; + case 'servervar': + $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']]; + break; } } } + } - // Retrieve all required status variables - if (count($statusVars)) { - $statusVarValues = PMA_DBI_fetch_result( - "SHOW GLOBAL STATUS - WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1); - } else { - $statusVarValues = array(); - } + $ret['x'] = microtime(true)*1000; - // Retrieve all required server variables - if (count($serverVars)) { - $serverVarValues = PMA_DBI_fetch_result( - "SHOW GLOBAL VARIABLES - WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1); - } else { - $serverVarValues = array(); - } - - // ...and now assign them - foreach ($ret as $chart_id => $chartNodes) { - foreach ($chartNodes as $node_id => $nodeDataPoints) { - foreach ($nodeDataPoints as $point_id => $dataPoint) { - switch($dataPoint['type']) { - case 'statusvar': - $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']]; - break; - case 'servervar': - $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']]; - break; - } - } - } - } - - $ret['x'] = microtime(true)*1000; - - exit(json_encode($ret)); + exit(json_encode($ret)); } } @@ -210,16 +210,18 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $type = strtolower(substr($row['sql_text'], 0, strpos($row['sql_text'], ' '))); switch($type) { - case 'insert': - case 'update': - // Cut off big inserts and updates, but append byte count therefor - if(strlen($row['sql_text']) > 220) - $row['sql_text'] = substr($row['sql_text'], 0, 200) . '... [' . - implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2)) . ']'; - - break; - default: - break; + case 'insert': + case 'update': + // Cut off big inserts and updates, but append byte count therefor + if (strlen($row['sql_text']) > 220) { + $row['sql_text'] = substr($row['sql_text'], 0, 200) + . '... [' + . implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2)) + . ']'; + } + break; + default: + break; } if(!isset($return['sum'][$type])) $return['sum'][$type] = 0; @@ -261,35 +263,37 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $return['sum'][$type] += $row['#']; switch($type) { - case 'insert': - // Group inserts if selected - if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) { - $insertTables[$matches[2]]++; - if ($insertTables[$matches[2]] > 1) { - $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]]; + case 'insert': + // Group inserts if selected + if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) { + $insertTables[$matches[2]]++; + if ($insertTables[$matches[2]] > 1) { + $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]]; - // Add a ... to the end of this query to indicate that there's been other queries - if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') - $return['rows'][$insertTablesFirst]['argument'] .= '
...'; + // Add a ... to the end of this query to indicate that there's been other queries + if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') + $return['rows'][$insertTablesFirst]['argument'] .= '
...'; - // Group this value, thus do not add to the result list - continue 2; - } else { - $insertTablesFirst = $i; - $insertTables[$matches[2]] += $row['#'] - 1; - } + // Group this value, thus do not add to the result list + continue 2; + } else { + $insertTablesFirst = $i; + $insertTables[$matches[2]] += $row['#'] - 1; } - // No break here + } + // No break here - case 'update': - // Cut off big inserts and updates, but append byte count therefor - if(strlen($row['argument']) > 220) - $row['argument'] = substr($row['argument'], 0, 200) . '... [' . - implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2) . ']'; + case 'update': + // Cut off big inserts and updates, but append byte count therefor + if(strlen($row['argument']) > 220) { + $row['argument'] = substr($row['argument'], 0, 200) + . '... [' + . implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2) + . ']'; + } + break; - break; - - default: break; + default: break; } $return['rows'][] = $row; @@ -623,19 +627,19 @@ if(PMA_DRIZZLE) { /* Ajax request refresh */ if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) { switch($_REQUEST['show']) { - case 'query_statistics': - printQueryStatistics(); - exit(); - case 'server_traffic': - printServerTraffic(); - exit(); - case 'variables_table': - // Prints the variables table - printVariablesTable(); - exit(); + case 'query_statistics': + printQueryStatistics(); + exit(); + case 'server_traffic': + printServerTraffic(); + exit(); + case 'variables_table': + // Prints the variables table + printVariablesTable(); + exit(); - default: - break; + default: + break; } } From 6f33d1366af39331653d29df5a739ee036ce2997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 09:32:26 +0200 Subject: [PATCH 13/14] Fix coding style --- server_status.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server_status.php b/server_status.php index ce4df7564e..6bd9fd6330 100644 --- a/server_status.php +++ b/server_status.php @@ -38,7 +38,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $num_procs = PMA_DBI_num_rows($result); $ret = array( - 'x' => microtime(true)*1000, + 'x' => microtime(true) * 1000, 'y_proc' => $num_procs, 'y_conn' => $c['Connections'] ); @@ -59,7 +59,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { //$sum=array_sum($queries); $ret = array( - 'x' => microtime(true)*1000, + 'x' => microtime(true) * 1000, 'y' => $questions, 'pointInfo' => $queries ); @@ -74,7 +74,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { OR Variable_name = 'Bytes_sent'", 0, 1); $ret = array( - 'x' => microtime(true)*1000, + 'x' => microtime(true) * 1000, 'y_sent' => $traffic['Bytes_sent'], 'y_received' => $traffic['Bytes_received'] ); @@ -183,7 +183,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } } - $ret['x'] = microtime(true)*1000; + $ret['x'] = microtime(true) * 1000; exit(json_encode($ret)); } @@ -649,7 +649,7 @@ $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost' PMA_AddJSCode('pma_token = \'' . $_SESSION[' PMA_token '] . "';\n" . 'url_query = \'' . str_replace('&', '&', PMA_generate_common_url($db)) . "';\n" . - 'server_time_diff = new Date().getTime() - ' . (microtime(true)*1000) . ";\n" . + 'server_time_diff = new Date().getTime() - ' . (microtime(true) * 1000) . ";\n" . 'server_os = \'' . PHP_OS . "';\n" . 'is_superuser = ' . (PMA_isSuperuser() ? 'true' : 'false') . ";\n" . 'server_db_isLocal = ' . ($server_db_isLocal ? 'true' : 'false') . ";\n" . From 61335cdc2ed5839ac2914c83c9508cd9e4a6e5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:30:56 +0200 Subject: [PATCH 14/14] Improve coding style --- server_status.php | 92 ++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/server_status.php b/server_status.php index 6bd9fd6330..7c2f30a658 100644 --- a/server_status.php +++ b/server_status.php @@ -15,8 +15,9 @@ if (! defined('PMA_NO_VARIABLES_IMPORT')) { define('PMA_NO_VARIABLES_IMPORT', true); } -if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) +if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $GLOBALS['is_header_sent'] = true; +} require_once './libraries/common.inc.php'; @@ -104,13 +105,15 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { * Also do some white list filtering on the names */ case 'servervar': - if (!preg_match('/[^a-zA-Z_]+/', $pName)) + if (!preg_match('/[^a-zA-Z_]+/', $pName)) { $serverVars[] = $pName; + } break; case 'statusvar': - if (!preg_match('/[^a-zA-Z_]+/', $pName)) + if (!preg_match('/[^a-zA-Z_]+/', $pName)) { $statusVars[] = $pName; + } break; case 'proc': @@ -123,8 +126,9 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { require_once('libraries/sysinfo.lib.php'); $sysinfo = getSysInfo(); } - if (!$cpuload) + if (!$cpuload) { $cpuload = $sysinfo->loadavg(); + } if (PHP_OS == 'Linux') { $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle']; @@ -139,8 +143,9 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { require_once('libraries/sysinfo.lib.php'); $sysinfo = getSysInfo(); } - if (!$memory) + if (!$memory) { $memory = $sysinfo->memory(); + } $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName]; break; @@ -190,7 +195,10 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } if (isset($_REQUEST['log_data'])) { - if(PMA_MYSQL_INT_VERSION < 50106) exit('""'); + if (PMA_MYSQL_INT_VERSION < 50106) { + /* FIXME: why this? */ + exit('""'); + } $start = intval($_REQUEST['time_start']); $end = intval($_REQUEST['time_end']); @@ -224,7 +232,9 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { break; } - if(!isset($return['sum'][$type])) $return['sum'][$type] = 0; + if (!isset($return['sum'][$type])) { + $return['sum'][$type] = 0; + } $return['sum'][$type] += $row['#']; $return['rows'][] = $row; } @@ -237,7 +247,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($return)); } - if($_REQUEST['type'] == 'general') { + if ($_REQUEST['type'] == 'general') { $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes']) ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : ''; @@ -259,20 +269,23 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { preg_match('/^(\w+)\s/', $row['argument'], $match); $type = strtolower($match[1]); - if(!isset($return['sum'][$type])) $return['sum'][$type] = 0; + if (!isset($return['sum'][$type])) { + $return['sum'][$type] = 0; + } $return['sum'][$type] += $row['#']; switch($type) { case 'insert': // Group inserts if selected - if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) { + if ($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) { $insertTables[$matches[2]]++; if ($insertTables[$matches[2]] > 1) { $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]]; // Add a ... to the end of this query to indicate that there's been other queries - if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') + if ($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') { $return['rows'][$insertTablesFirst]['argument'] .= '
...'; + } // Group this value, thus do not add to the result list continue 2; @@ -285,7 +298,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { case 'update': // Cut off big inserts and updates, but append byte count therefor - if(strlen($row['argument']) > 220) { + if (strlen($row['argument']) > 220) { $row['argument'] = substr($row['argument'], 0, 200) . '... [' . implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2) @@ -310,12 +323,15 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } if (isset($_REQUEST['logging_vars'])) { - if(isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) { + if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) { $value = PMA_sqlAddslashes($_REQUEST['varValue']); - if(!is_numeric($value)) $value="'" . $value . "'"; + if (!is_numeric($value)) { + $value="'" . $value . "'"; + } - if(! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])) + if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])) { PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value); + } } @@ -323,14 +339,16 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($loggingVars)); } - if(isset($_REQUEST['query_analyzer'])) { + if (isset($_REQUEST['query_analyzer'])) { $return = array(); - if(strlen($_REQUEST['database'])) + if (strlen($_REQUEST['database'])) { PMA_DBI_select_db($_REQUEST['database']); + } - if ($profiling = PMA_profilingSupported()) + if ($profiling = PMA_profilingSupported()) { PMA_DBI_query('SET PROFILING=1;'); + } // Do not cache query $query = preg_replace('/^(\s*SELECT)/i', '\\1 SQL_NO_CACHE', $_REQUEST['query']); @@ -348,7 +366,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { PMA_DBI_free_result($result); - if($profiling) { + if ($profiling) { $return['profiling'] = array(); $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq'); while ($row = PMA_DBI_fetch_assoc($result)) { @@ -360,7 +378,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($return)); } - if(isset($_REQUEST['advisor'])) { + if (isset($_REQUEST['advisor'])) { include('libraries/Advisor.class.php'); $advisor = new Advisor(); exit(json_encode($advisor->run())); @@ -610,7 +628,9 @@ foreach ($server_status as $name => $value) { foreach ($allocations as $filter => $section) { if (strpos($name, $filter) !== false) { $allocationMap[$name] = $section; - if ($section == 'com' && $value > 0) $used_queries[$name] = $value; + if ($section == 'com' && $value > 0) { + $used_queries[$name] = $value; + } break; // Only exits inner loop } } @@ -776,7 +796,9 @@ echo __('Runtime Information'); echo ' '; $i=0; foreach ($section_links as $link_name => $link_url) { - if ($i > 0) echo ', '; + if ($i > 0) { + echo ', '; + } if ('doc' == $link_name) { echo PMA_showMySQLDocu($link_url, $link_url); } else { @@ -898,9 +920,11 @@ function printQueryStatistics() $name = str_replace(array('Com_', '_'), array('', ' '), $name); // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already - if ($value < $query_sum * 0.02 && count($chart_json)>6) + if ($value < $query_sum * 0.02 && count($chart_json)>6) { $other_sum += $value; - else $chart_json[$name] = $value; + } else { + $chart_json[$name] = $value; + } ?> @@ -919,8 +943,9 @@ function printQueryStatistics()