Skip to content

Commit

Permalink
Fix calculation of pos after delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tithugues committed Nov 3, 2013
1 parent 1aedeef commit d3adbca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
9 changes: 7 additions & 2 deletions libraries/mult_submits.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ function PMA_getQueryStrFromSelected(
}

$selected_cnt = count($selected);
$deletes = false;

for ($i = 0; $i < $selected_cnt; $i++) {
switch ($query_type) {
case 'row_delete':
$deletes = true;
$a_query = $selected[$i];
$run_parts = true;
break;
Expand Down Expand Up @@ -153,6 +155,7 @@ function PMA_getQueryStrFromSelected(
break;

case 'empty_tbl':
$deletes = true;
$a_query = 'TRUNCATE ';
$a_query .= PMA_Util::backquote($selected[$i]);
$run_parts = true;
Expand Down Expand Up @@ -267,12 +270,14 @@ function PMA_getQueryStrFromSelected(
PMA_clearTransformations($db, $selected[$i]);
} else if ($query_type == 'drop_fld') {
PMA_clearTransformations($db, $table, $selected[$i]);
} elseif ($query_type == 'row_delete') {
//PMA_updatePos($db, $table);
}
} // end if
} // end for

if ($deletes) {
$_REQUEST['pos'] = PMA_calculatePosForLastPage($db, $table, $_REQUEST['pos']);
}

return array(
$result, $rebuild_database_list, $reload,
$run_parts, $use_sql, $sql_query, $sql_query_views
Expand Down
30 changes: 22 additions & 8 deletions libraries/sql.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,7 @@ function PMA_addBookmark($pmaAbsoluteUri, $goto)
function PMA_findRealEndOfRows($db, $table)
{
$unlim_num_rows = PMA_Table::countRecords($db, $table, true);
$_SESSION['tmpval']['pos'] = @((ceil(
$unlim_num_rows / $_SESSION['tmpval']['max_rows']
) - 1) * $_SESSION['tmpval']['max_rows']);
$_SESSION['tmpval']['pos'] = PMA_getStartPosToDisplayRow($unlim_num_rows);

return $unlim_num_rows;
}
Expand Down Expand Up @@ -2337,22 +2335,38 @@ function PMA_executeQueryAndSendQueryResponse($analyzed_sql_results,
}

/**
* Update pos if pos is higher than number of rows of displayed table
* Function to define pos to display a row
*
* @param Int $number_of_line Number of the line to display
*
* @return Int Start position to display the line
*/
function PMA_getStartPosToDisplayRow($number_of_line)
{
return @(
(ceil($number_of_line / $_SESSION['tmpval']['max_rows']) - 1)
* $_SESSION['tmpval']['max_rows']
);
}

/**
* 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 $pos Initial position
*
* @return Int Number of rows
* @return Int Number of pos to display last page
*/
function PMA_updatePos($db, $table)
function PMA_calculatePosForLastPage($db, $table, $pos = 0)
{
$unlim_num_rows = PMA_Table::countRecords($db, $table, true);
//If position is higher than number of rows
if ($unlim_num_rows <= $_SESSION['tmpval']['pos']) {
PMA_findRealEndOfRows($db, $table);
$pos = PMA_getStartPosToDisplayRow($unlim_num_rows);
}

return $unlim_num_rows;
return $pos;
}

?>

0 comments on commit d3adbca

Please sign in to comment.