From 57bea0630acc3d36f7f771a96fb84aebbea1ab3d Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Tue, 23 Aug 2011 22:14:15 +0200 Subject: [PATCH] Use PMA_DBI_get_table_indexes_sql() only when really needed, in all other cases use PMA_DBI_get_table_indexes() --- db_datadict.php | 8 ++------ db_qbe.php | 4 ++-- libraries/Index.class.php | 2 +- libraries/Tracker.class.php | 3 --- libraries/database_interface.lib.php | 4 ++-- libraries/export/htmlword.php | 8 +++----- libraries/export/latex.php | 8 +++----- libraries/export/odt.php | 8 +++----- libraries/export/texytext.php | 8 +++----- 9 files changed, 19 insertions(+), 34 deletions(-) diff --git a/db_datadict.php b/db_datadict.php index 538bccd427..f580e21e5a 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -76,7 +76,7 @@ foreach($tables as $table) { */ PMA_DBI_select_db($db); - $result = PMA_DBI_query(PMA_DBI_get_table_indexes_sql($db, $table)); + $indexes = PMA_DBI_get_table_indexes($db, $table); $primary = ''; $indexes = array(); $lastIndex = ''; @@ -84,7 +84,7 @@ foreach($tables as $table) { $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view - while ($row = PMA_DBI_fetch_assoc($result)) { + foreach ($indexes as $row) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; @@ -111,10 +111,6 @@ foreach($tables as $table) { } } // end while - if ($result) { - PMA_DBI_free_result($result); - } - /** * Gets columns properties diff --git a/db_qbe.php b/db_qbe.php index 2afdc41f08..66d670b903 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -755,8 +755,8 @@ if (isset($Field) && count($Field) > 0) { PMA_DBI_select_db($db); foreach ($tab_all as $tab) { - $ind_rs = PMA_DBI_query(PMA_DBI_get_table_indexes_sql($db, $tab)); - while ($ind = PMA_DBI_fetch_assoc($ind_rs)) { + $indexes = PMA_DBI_get_table_indexes($db, $tab); + foreach ($indexes as $ind) { $col1 = $tab . '.' . $ind['Column_name']; if (isset($col_all[$col1])) { if ($ind['Non_unique'] == 0) { diff --git a/libraries/Index.class.php b/libraries/Index.class.php index 95ee346a66..47c9950ee4 100644 --- a/libraries/Index.class.php +++ b/libraries/Index.class.php @@ -157,7 +157,7 @@ class PMA_Index return true; } - $_raw_indexes = PMA_DBI_fetch_result(PMA_DBI_get_table_indexes_sql($schema, $table)); + $_raw_indexes = PMA_DBI_get_table_indexes($schema, $table); foreach ($_raw_indexes as $_each_index) { $_each_index['Schema'] = $schema; if (! isset(PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']])) { diff --git a/libraries/Tracker.class.php b/libraries/Tracker.class.php index a624000338..97f62f05a3 100644 --- a/libraries/Tracker.class.php +++ b/libraries/Tracker.class.php @@ -259,9 +259,6 @@ class PMA_Tracker } $indexes = PMA_DBI_get_table_indexes($dbname, $tablename); - if (!$indexes) { - $indexes = array(); - } $snapshot = array('COLUMNS' => $columns, 'INDEXES' => $indexes); $snapshot = serialize($snapshot); diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 30204a0989..ebc77c02ba 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -1104,7 +1104,7 @@ function PMA_DBI_get_table_indexes_sql($database, $table, $where = null) } /** -* array PMA_DBI_get_table_indexes($database, $table, $link = null) +* Returns indexes od a table * * @param string $database name of database * @param string $table name of the table whose indexes are to be retreived @@ -1117,7 +1117,7 @@ function PMA_DBI_get_table_indexes($database, $table, $link = null) $indexes = PMA_DBI_fetch_result($sql, null, null, $link); if (! is_array($indexes) || count($indexes) < 1) { - return false; + return array(); } return $indexes; } diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php index ac8ee52891..7f047033cd 100644 --- a/libraries/export/htmlword.php +++ b/libraries/export/htmlword.php @@ -199,15 +199,13 @@ if (isset($plugin_list)) { /** * Get the unique keys in the table */ - $keys_query = PMA_DBI_get_table_indexes_sql($db, $table); - $keys_result = PMA_DBI_query($keys_query); - $unique_keys = array(); - while ($key = PMA_DBI_fetch_assoc($keys_result)) { + $unique_keys = array(); + $keys = PMA_DBI_get_table_indexes($db, $table); + foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } - PMA_DBI_free_result($keys_result); /** * Gets fields properties diff --git a/libraries/export/latex.php b/libraries/export/latex.php index 429cae416a..1e84820a4d 100644 --- a/libraries/export/latex.php +++ b/libraries/export/latex.php @@ -302,15 +302,13 @@ if (isset($plugin_list)) { /** * Get the unique keys in the table */ - $keys_query = PMA_DBI_get_table_indexes_sql($db, $table); - $keys_result = PMA_DBI_query($keys_query); - $unique_keys = array(); - while ($key = PMA_DBI_fetch_assoc($keys_result)) { + $unique_keys = array(); + $keys = PMA_DBI_get_table_indexes($db, $table); + foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } - PMA_DBI_free_result($keys_result); /** * Gets fields properties diff --git a/libraries/export/odt.php b/libraries/export/odt.php index 7cc411a537..fc2b5368e9 100644 --- a/libraries/export/odt.php +++ b/libraries/export/odt.php @@ -237,15 +237,13 @@ if (isset($plugin_list)) { /** * Get the unique keys in the table */ - $keys_query = PMA_DBI_get_table_indexes_sql($db, $table); - $keys_result = PMA_DBI_query($keys_query); - $unique_keys = array(); - while ($key = PMA_DBI_fetch_assoc($keys_result)) { + $unique_keys = array(); + $keys = PMA_DBI_get_table_indexes($db, $table); + foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } - PMA_DBI_free_result($keys_result); /** * Gets fields properties diff --git a/libraries/export/texytext.php b/libraries/export/texytext.php index 6736806ec7..351ce718e5 100644 --- a/libraries/export/texytext.php +++ b/libraries/export/texytext.php @@ -181,15 +181,13 @@ if (isset($plugin_list)) { /** * Get the unique keys in the table */ - $keys_query = PMA_DBI_get_table_indexes_sql($db, $table); - $keys_result = PMA_DBI_query($keys_query); - $unique_keys = array(); - while ($key = PMA_DBI_fetch_assoc($keys_result)) { + $unique_keys = array(); + $keys = PMA_DBI_get_table_indexes($db, $table); + foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } - PMA_DBI_free_result($keys_result); /** * Gets fields properties -- 2.11.4.GIT