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 f3777d3dc4
commit 0eab8db4a4
2 changed files with 42 additions and 29 deletions

View File

@@ -17,7 +17,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA
- [interface] sanitize the table comments in table print view, - [interface] sanitize the table comments in table print view,
thanks to Norman Hippert thanks to Norman Hippert
- bug #1939031 Auto_Increment selected for TimeStamp by Default - bug #1939031 Auto_Increment selected for TimeStamp by Default
- bug #1910621 [display] part 2: do not display a BINARY content as text
2.11.6.0 (2008-04-29) 2.11.6.0 (2008-04-29)
- bug #1903724 [interface] Displaying of very large queries in error message - bug #1903724 [interface] Displaying of very large queries in error message

View File

@@ -1233,7 +1233,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// n u m e r i c // n u m e r i c
if ($meta->numeric == 1) { if ($meta->numeric == 1) {
// lem9: if two fields have the same name (this is possible // lem9: if two fields have the same name (this is possible
// with self-join queries, for example), using $meta->name // with self-join queries, for example), using $meta->name
// will show both fields NULL even if only one is NULL, // will show both fields NULL even if only one is NULL,
@@ -1244,7 +1243,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// mysql_fetch_array() is MYSQL_BOTH, so we always get // mysql_fetch_array() is MYSQL_BOTH, so we always get
// associative and numeric indices? // associative and numeric indices?
//if (!isset($row[$meta->name])
if (!isset($row[$i]) || is_null($row[$i])) { 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"; $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
} elseif ($row[$i] != '') { } elseif ($row[$i] != '') {
@@ -1308,27 +1306,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// of the fields. // of the fields.
$field_flags = PMA_DBI_field_flags($dt_result, $i); $field_flags = PMA_DBI_field_flags($dt_result, $i);
if (stristr($field_flags, 'BINARY')) { if (stristr($field_flags, 'BINARY')) {
$blobtext = '[BLOB'; $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
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);
$vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>'; $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
unset($blobtext);
} else { } else {
if (!isset($row[$i]) || is_null($row[$i])) { 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"; $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
@@ -1364,12 +1344,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) { if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
$row[$i] = PMA_printable_bit_value($row[$i], $meta->length); $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
} elseif (stristr($field_flags, 'BINARY')) { } elseif (stristr($field_flags, 'BINARY')) {
$row[$i] = str_replace("\x00", '\0', $row[$i]); $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
$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));
} }
// loic1: displays all space characters, 4 space // loic1: displays all space characters, 4 space
// characters for tabulations and <cr>/<lf> // characters for tabulations and <cr>/<lf>
@@ -2128,4 +2103,42 @@ function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
echo '</fieldset><br />'; 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);
}
?> ?>