Counts and returns (or displays) the number of records in a table
public countRecords ( boolean $force_exact = false ) : mixed | ||
$force_exact | boolean | whether to force an exact count |
Résultat | mixed | the number of records if "retain" param is true, otherwise true |
/** * Function to calculate new pos if pos is higher than number of rows * of displayed table * * @param String $db Database name * @param String $table Table name * @param Int|null $pos Initial position * * @return Int Number of pos to display last page */ function PMA_calculatePosForLastPage($db, $table, $pos) { if (null === $pos) { $pos = $_SESSION['tmpval']['pos']; } $_table = new Table($table, $db); $unlim_num_rows = $_table->countRecords(true); //If position is higher than number of rows if ($unlim_num_rows <= $pos && 0 != $pos) { $pos = PMA_getStartPosToDisplayRow($unlim_num_rows); } return $pos; }
/** * Test for countRecords * * @return void */ public function testCountRecords() { $map = array(array(array('PMA', 'PMA_BookMark'), null, array('Comment' => "Comment222", 'TABLE_TYPE' => "VIEW")), array(array('PMA', 'PMA_BookMark', 'TABLE_TYPE'), null, 'VIEW')); $GLOBALS['dbi']->expects($this->any())->method('getCachedTableContent')->will($this->returnValueMap($map)); $table = 'PMA_BookMark'; $db = 'PMA'; $tableObj = new Table($table, $db); $return = $tableObj->countRecords(true); $expect = 20; $this->assertEquals($expect, $return); }
/** * Provides the main table to form the LEFT JOIN clause * * @param array $search_tables Tables involved in the search * @param array $search_columns Columns involved in the search * @param array $where_clause_columns Columns having criteria where clause * @param array $where_clause_tables Tables having criteria where clause * * @return string table name */ private function _getMasterTable($search_tables, $search_columns, $where_clause_columns, $where_clause_tables) { if (count($where_clause_tables) == 1) { // If there is exactly one column that has a decent where-clause // we will just use this $master = key($where_clause_tables); return $master; } // Now let's find out which of the tables has an index // (When the control user is the same as the normal user // because he is using one of his databases as pmadb, // the last db selected is not always the one where we need to work) $candidate_columns = $this->_getLeftJoinColumnCandidates($search_tables, $search_columns, $where_clause_columns); // Generally, we need to display all the rows of foreign (referenced) // table, whether they have any matching row in child table or not. // So we select candidate tables which are foreign tables. $foreign_tables = array(); foreach ($candidate_columns as $one_table) { $foreigners = PMA_getForeigners($this->_db, $one_table); foreach ($foreigners as $key => $foreigner) { if ($key != 'foreign_keys_data') { if (in_array($foreigner['foreign_table'], $candidate_columns)) { $foreign_tables[$foreigner['foreign_table']] = $foreigner['foreign_table']; } continue; } foreach ($foreigner as $one_key) { if (in_array($one_key['ref_table_name'], $candidate_columns)) { $foreign_tables[$one_key['ref_table_name']] = $one_key['ref_table_name']; } } } } if (count($foreign_tables)) { $candidate_columns = $foreign_tables; } // If our array of candidates has more than one member we'll just // find the smallest table. // Of course the actual query would be faster if we check for // the Criteria which gives the smallest result set in its table, // but it would take too much time to check this if (!(count($candidate_columns) > 1)) { // Only one single candidate return reset($candidate_columns); } // Of course we only want to check each table once $checked_tables = $candidate_columns; $tsize = array(); $csize = array(); foreach ($candidate_columns as $table) { if ($checked_tables[$table] != 1) { $_table = new Table($table, $this->_db); $tsize[$table] = $_table->countRecords(); $checked_tables[$table] = 1; } $csize[$table] = $tsize[$table]; } // Return largest table return array_search(max($csize), $csize); }
/** * Prints Html For Export Options Rows * * @param String $db Selected DB * @param String $table Selected Table * @param String $unlim_num_rows Num of Rows * * @return string */ function PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows) { $html = '<div class="exportoptions" id="rows">'; $html .= '<h3>' . __('Rows:') . '</h3>'; $html .= '<ul>'; $html .= '<li>'; $html .= '<input type="radio" name="allrows" value="0" id="radio_allrows_0"'; if (isset($_GET['allrows']) && $_GET['allrows'] == 0) { $html .= ' checked="checked"'; } $html .= '/>'; $html .= '<label for ="radio_allrows_0">' . __('Dump some row(s)') . '</label>'; $html .= '<ul>'; $html .= '<li>'; $html .= '<label for="limit_to">' . __('Number of rows:') . '</label>'; $html .= '<input type="text" id="limit_to" name="limit_to" size="5" value="'; if (isset($_GET['limit_to'])) { $html .= htmlspecialchars($_GET['limit_to']); } elseif (!empty($unlim_num_rows)) { $html .= $unlim_num_rows; } else { $_table = new Table($table, $db); $html .= $_table->countRecords(); } $html .= '" onfocus="this.select()" />'; $html .= '</li>'; $html .= '<li>'; $html .= '<label for="limit_from">' . __('Row to begin at:') . '</label>'; $html .= '<input type="text" id="limit_from" name="limit_from" value="'; if (isset($_GET['limit_from'])) { $html .= htmlspecialchars($_GET['limit_from']); } else { $html .= '0'; } $html .= '" size="5" onfocus="this.select()" />'; $html .= '</li>'; $html .= '</ul>'; $html .= '</li>'; $html .= '<li>'; $html .= '<input type="radio" name="allrows" value="1" id="radio_allrows_1"'; if (!isset($_GET['allrows']) || $_GET['allrows'] == 1) { $html .= ' checked="checked"'; } $html .= '/>'; $html .= ' <label for="radio_allrows_1">' . __('Dump all rows') . '</label>'; $html .= '</li>'; $html .= '</ul>'; $html .= '</div>'; return $html; }
foreach ($mime_map as $transformation) { $column_name = $transformation['column_name']; foreach ($transformation_types as $type) { $file = PMA_securePath($transformation[$type]); $extra_data = PMA_transformEditedValues($db, $table, $transformation, $edited_values, $file, $column_name, $extra_data, $type); } } // end of loop for each $mime_map } // Need to check the inline edited value can be truncated by MySQL // without informing while saving $column_name = $_REQUEST['fields_name']['multi_edit'][0][0]; PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData($db, $table, $column_name, $extra_data); /**Get the total row count of the table*/ $_table = new Table($_REQUEST['table'], $_REQUEST['db']); $extra_data['row_count'] = $_table->countRecords(); $extra_data['sql_query'] = PMA\libraries\Util::getMessage($message, $GLOBALS['display_query']); $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus($message->isSuccess()); $response->addJSON('message', $message); $response->addJSON($extra_data); exit; } if (!empty($return_to_sql_query)) { $disp_query = $GLOBALS['sql_query']; $disp_message = $message; unset($message); $GLOBALS['sql_query'] = $return_to_sql_query; } $scripts->addFile('tbl_change.js'); $active_page = $goto_include;