bug #1910621 [display] part 2: do not display a BINARY content as text

This commit is contained in:
Marc Delisle
2008-05-07 10:28:12 +00:00
parent 5cfa78a087
commit 14edea6b1a
2 changed files with 42 additions and 27 deletions

View File

@@ -63,6 +63,7 @@ danbarry
- bug #1955386 [session] Overriding session.hash_bits_per_character
- [interface] sanitize the table comments in table print view,
thanks to Norman Hippert
- bug #1910621 [display] part 2: do not display a BINARY content as text
2.11.6.0 (2008-04-29)
- bug #1903724 [interface] Displaying of very large queries in error message

View File

@@ -1210,7 +1210,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// mysql_fetch_array() is MYSQL_BOTH, so we always get
// associative and numeric indices?
//if (!isset($row[$meta->name])
if (!isset($row[$i]) || is_null($row[$i])) {
$vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
} elseif ($row[$i] != '') {
@@ -1285,27 +1284,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// of the fields.
$field_flags = PMA_DBI_field_flags($dt_result, $i);
if (stristr($field_flags, 'BINARY')) {
$blobtext = '[BLOB';
if (!isset($row[$i]) || is_null($row[$i])) {
$blobtext .= ' - NULL';
$blob_size = 0;
} elseif (isset($row[$i])) {
$blob_size = strlen($row[$i]);
$display_blob_size = PMA_formatByteDown($blob_size, 3, 1);
$blobtext .= ' - '. $display_blob_size[0] . ' ' . $display_blob_size[1];
unset($display_blob_size);
}
$blobtext .= ']';
if (strpos($transform_function, 'octetstream')) {
$blobtext = $row[$i];
}
if ($blob_size > 0) {
$blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
}
unset($blob_size);
$blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
$vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
unset($blobtext);
} else {
if (!isset($row[$i]) || is_null($row[$i])) {
$vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
@@ -1341,12 +1322,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
$row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
} elseif (stristr($field_flags, 'BINARY')) {
$row[$i] = str_replace("\x00", '\0', $row[$i]);
$row[$i] = str_replace("\x08", '\b', $row[$i]);
$row[$i] = str_replace("\x0a", '\n', $row[$i]);
$row[$i] = str_replace("\x0d", '\r', $row[$i]);
$row[$i] = str_replace("\x1a", '\Z', $row[$i]);
$row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
$row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
}
// loic1: displays all space characters, 4 space
// characters for tabulations and <cr>/<lf>
@@ -2117,4 +2093,42 @@ function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
echo '</fieldset><br />';
}
}
/**
* Verifies what to do with non-printable contents (binary or BLOB)
* in Browse mode.
*
* @uses is_null()
* @uses isset()
* @uses strlen()
* @uses PMA_formatByteDown()
* @uses strpos()
* @param string $category BLOB|BINARY
* @param string $content the binary content
* @param string $transform_function
* @param string $transform_options
* @param string $default_function
* @param object $meta the meta-information about this field
* @return mixed string or float
*/
function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
$result = '[' . $category;
if (is_null($content)) {
$result .= ' - NULL';
$size = 0;
} elseif (isset($content)) {
$size = strlen($content);
$display_size = PMA_formatByteDown($size, 3, 1);
$result .= ' - '. $display_size[0] . $display_size[1];
}
$result .= ']';
if (strpos($transform_function, 'octetstream')) {
$result = $content;
}
if ($size > 0) {
$result = ($default_function != $transform_function ? $transform_function($result, $transform_options, $meta) : $default_function($result, array(), $meta));
}
return($result);
}
?>