diff --git a/libraries/DBQbe.class.php b/libraries/DBQbe.class.php index d2de811bd3..343a7f38f6 100644 --- a/libraries/DBQbe.class.php +++ b/libraries/DBQbe.class.php @@ -1532,32 +1532,40 @@ class PMA_DbQbe private function _getFromClause() { $from_clause = ''; - if (isset($_POST['criteriaColumn']) && count($_POST['criteriaColumn']) > 0) { - // Initialize some variables - $search_tables = $search_columns = array(); + if (!isset($_POST['criteriaColumn']) + || count($_POST['criteriaColumn']) <= 0 + ) { + return $from_clause; + } - // We only start this if we have fields, otherwise it would be dumb - foreach ($_POST['criteriaColumn'] as $value) { - $parts = explode('.', $value); - if (! empty($parts[0]) && ! empty($parts[1])) { - $table = str_replace('`', '', $parts[0]); - $search_tables[$table] = $table; - $search_columns[] = $table . '.' . str_replace('`', '', $parts[1]); - } - } // end while + // Initialize some variables + $search_tables = $search_columns = array(); - // Create LEFT JOINS out of Relations - $from_clause = $this->_getJoinForFromClause($search_tables, $search_columns); - - // In case relations are not defined, just generate the FROM clause - // from the list of tables, however we don't generate any JOIN - if (empty($from_clause)) { - // Create cartesian product - $from_clause = implode( - ", ", array_map('PMA_Util::backquote', $search_tables) + // We only start this if we have fields, otherwise it would be dumb + foreach ($_POST['criteriaColumn'] as $value) { + $parts = explode('.', $value); + if (! empty($parts[0]) && ! empty($parts[1])) { + $table = str_replace('`', '', $parts[0]); + $search_tables[$table] = $table; + $search_columns[] = $table . '.' . str_replace( + '`', '', $parts[1] ); } - } // end count($_POST['criteriaColumn']) > 0 + } // end while + + // Create LEFT JOINS out of Relations + $from_clause = $this->_getJoinForFromClause( + $search_tables, $search_columns + ); + + // In case relations are not defined, just generate the FROM clause + // from the list of tables, however we don't generate any JOIN + if (empty($from_clause)) { + // Create cartesian product + $from_clause = implode( + ", ", array_map('PMA_Util::backquote', $search_tables) + ); + } return $from_clause; } @@ -1619,36 +1627,38 @@ class PMA_DbQbe foreach ($columnReferences as $reference) { // Only from this schema - if ($reference['table_schema'] == $this->_db) { - $table = $reference['table_name']; + if ($reference['table_schema'] != $this->_db) { + continue; + } - $this->_loadRelationsForTable($relations, $table); + $table = $reference['table_name']; - // Make copies - $tempFinalized = $finalized; - $tempSearchTables = $searchTables; - $tempSearchTables[] = $table; + $this->_loadRelationsForTable($relations, $table); - // Try joining with the added table - $this->_fillJoinClauses( - $tempFinalized, $relations, $tempSearchTables - ); + // Make copies + $tempFinalized = $finalized; + $tempSearchTables = $searchTables; + $tempSearchTables[] = $table; - $tempUnfinalized = array_diff( - $tempSearchTables, array_keys($tempFinalized) - ); - // Take greedy approach. - // If the unfinalized count drops we keep the new table - // and switch temporary varibles with the original ones - if (count($tempUnfinalized) < count($unfinalized)) { - $finalized = $tempFinalized; - $searchTables = $tempSearchTables; - } + // Try joining with the added table + $this->_fillJoinClauses( + $tempFinalized, $relations, $tempSearchTables + ); - // We are done if no unfinalized tables anymore - if (count($tempUnfinalized) == 0) { - break 3; - } + $tempUnfinalized = array_diff( + $tempSearchTables, array_keys($tempFinalized) + ); + // Take greedy approach. + // If the unfinalized count drops we keep the new table + // and switch temporary varibles with the original ones + if (count($tempUnfinalized) < count($unfinalized)) { + $finalized = $tempFinalized; + $searchTables = $tempSearchTables; + } + + // We are done if no unfinalized tables anymore + if (count($tempUnfinalized) == 0) { + break 3; } } } diff --git a/libraries/DatabaseInterface.class.php b/libraries/DatabaseInterface.class.php index d4c774e3c1..b6b75ecba4 100644 --- a/libraries/DatabaseInterface.class.php +++ b/libraries/DatabaseInterface.class.php @@ -1087,47 +1087,51 @@ class PMA_DatabaseInterface $databases[$database_name]['DEFAULT_COLLATION_NAME'] = PMA_getDbCollation($database_name); - if ($force_stats) { - - // get additional info about tables - $databases[$database_name]['SCHEMA_TABLES'] = 0; - $databases[$database_name]['SCHEMA_TABLE_ROWS'] = 0; - $databases[$database_name]['SCHEMA_DATA_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_INDEX_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_DATA_FREE'] = 0; - - $res = $this->query( - 'SHOW TABLE STATUS FROM ' - . PMA_Util::backquote($database_name) . ';' - ); - - if ($res !== false) { - while ($row = $this->fetchAssoc($res)) { - $databases[$database_name]['SCHEMA_TABLES']++; - $databases[$database_name]['SCHEMA_TABLE_ROWS'] - += $row['Rows']; - $databases[$database_name]['SCHEMA_DATA_LENGTH'] - += $row['Data_length']; - $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] - += $row['Max_data_length']; - $databases[$database_name]['SCHEMA_INDEX_LENGTH'] - += $row['Index_length']; - - // for InnoDB, this does not contain the number of - // overhead bytes but the total free space - if ('InnoDB' != $row['Engine']) { - $databases[$database_name]['SCHEMA_DATA_FREE'] - += $row['Data_free']; - } - $databases[$database_name]['SCHEMA_LENGTH'] - += $row['Data_length'] + $row['Index_length']; - } - $this->freeResult($res); - } - unset($res); + if (!$force_stats) { + continue; } + + // get additional info about tables + $databases[$database_name]['SCHEMA_TABLES'] = 0; + $databases[$database_name]['SCHEMA_TABLE_ROWS'] = 0; + $databases[$database_name]['SCHEMA_DATA_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_INDEX_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_DATA_FREE'] = 0; + + $res = $this->query( + 'SHOW TABLE STATUS FROM ' + . PMA_Util::backquote($database_name) . ';' + ); + + if ($res === false) { + unset($res); + continue; + } + + while ($row = $this->fetchAssoc($res)) { + $databases[$database_name]['SCHEMA_TABLES']++; + $databases[$database_name]['SCHEMA_TABLE_ROWS'] + += $row['Rows']; + $databases[$database_name]['SCHEMA_DATA_LENGTH'] + += $row['Data_length']; + $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] + += $row['Max_data_length']; + $databases[$database_name]['SCHEMA_INDEX_LENGTH'] + += $row['Index_length']; + + // for InnoDB, this does not contain the number of + // overhead bytes but the total free space + if ('InnoDB' != $row['Engine']) { + $databases[$database_name]['SCHEMA_DATA_FREE'] + += $row['Data_free']; + } + $databases[$database_name]['SCHEMA_LENGTH'] + += $row['Data_length'] + $row['Index_length']; + } + $this->freeResult($res); + unset($res); } } diff --git a/libraries/controllers/TableSearchController.class.php b/libraries/controllers/TableSearchController.class.php index d09d4a54d7..ea6c5a5ed4 100644 --- a/libraries/controllers/TableSearchController.class.php +++ b/libraries/controllers/TableSearchController.class.php @@ -304,8 +304,8 @@ class TableSearchController extends TableController { // Defines the url to return to in case of error in the next sql // statement $err_url = $goto . PMA_URL_getCommon( - array('db' => $this->db, 'table' => $this->table) - ); + array('db' => $this->db, 'table' => $this->table) + ); //Set default datalabel if not selected if (!isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') { diff --git a/libraries/export.lib.php b/libraries/export.lib.php index 7fe01cefe1..6253f69f64 100644 --- a/libraries/export.lib.php +++ b/libraries/export.lib.php @@ -597,7 +597,8 @@ function PMA_exportDatabase( $db_alias = !empty($aliases[$db]['alias']) ? $aliases[$db]['alias'] : ''; - // If single file, add DB header and Create but don't store in $dump_buffer_objects + // If single file, add DB header and Create but don't store in + // $dump_buffer_objects if (! $separate_files == 'database') { if (! $export_plugin->exportDBHeader($db, $db_alias)) { return; @@ -651,16 +652,15 @@ function PMA_exportDatabase( // for a view, export a stand-in definition of the table // to resolve view dependencies (only when it's a single-file export) if ($is_view) { - if ($separate_files == '') { - if (isset($GLOBALS['sql_create_view'])) { - if (! $export_plugin->exportStructure( - $db, $table, $crlf, $err_url, 'stand_in', - $export_type, $do_relation, $do_comments, - $do_mime, $do_dates, $aliases - )) { - break; - } - } + if ($separate_files == '' + && isset($GLOBALS['sql_create_view']) + && ! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, 'stand_in', + $export_type, $do_relation, $do_comments, + $do_mime, $do_dates, $aliases + ) + ) { + break; } } else if (isset($GLOBALS['sql_create_table'])) { diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index de926bfd5e..7df6c5ad88 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -386,19 +386,24 @@ class Node $query = "SHOW DATABASES "; $query .= $this->_getWhereClause('Database', $searchClause); $handle = $GLOBALS['dbi']->tryQuery($query); - if ($handle !== false) { - $count = 0; - if ($GLOBALS['dbi']->dataSeek($handle, $pos)) { - while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { - if ($count < $maxItems) { - $retval[] = $arr[0]; - $count++; - } else { - break; - } - } + if ($handle === false) { + return $retval; + } + + $count = 0; + if (!$GLOBALS['dbi']->dataSeek($handle, $pos)) { + return $retval; + } + + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { + if ($count < $maxItems) { + $retval[] = $arr[0]; + $count++; + } else { + break; } } + return $retval; } diff --git a/tbl_replace.php b/tbl_replace.php index 3bbf69aeaf..f701a75f93 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -425,7 +425,6 @@ if ($response->isAjax() && ! isset($_POST['ajax_page_request'])) { /**Get the total row count of the table*/ $_table = new PMA_Table($_REQUEST['table'], $_REQUEST['db']); - $extra_data['row_count'] = $extra_data['row_count'] = $_table->countRecords(); $extra_data['sql_query']