bug #1926357 [data] BIT defaults displayed incorrectly

This commit is contained in:
Marc Delisle
2008-04-02 17:19:59 +00:00
parent c44c681d35
commit 42a4a8c24b
6 changed files with 73 additions and 19 deletions

View File

@@ -66,6 +66,7 @@ danbarry
thanks to Tony Marston - tonymarston
- bug #1918531 [compatibility] Navigation isn't w3.org valid
thanks to Michael Keck - mkkeck
- bug #1926357 [data] BIT defaults displayed incorrectly (todo: export?)
2.11.5.1 (2008-03-29)
- bug #1909711 [security] Sensitive data in session files

View File

@@ -2442,4 +2442,50 @@ function PMA_cacheSet($var, $val = null, $server = 0)
$_SESSION['cache']['server_' . $server][$var] = $val;
}
/**
* Converts a bit value to printable format;
* in MySQL a BIT field can be from 1 to 64 bits so we need this
* function because in PHP, decbin() supports only 32 bits
*
* @uses ceil()
* @uses decbin()
* @uses ord()
* @uses substr()
* @uses sprintf()
* @param numeric $value coming from a BIT field
* @param integer $length
* @return string the printable value
*/
function PMA_printable_bit_value($value, $length) {
$printable = '';
for ($i = 0; $i < ceil($length / 8); $i++) {
$printable .= sprintf('%08d', decbin(ord(substr($value, $i, 1))));
}
$printable = substr($printable, -$length);
return $printable;
}
/**
* Extracts the true field type and length from a field type spec
*
* @uses strpos()
* @uses chop()
* @uses substr()
* @param string $fieldspec
* @return array associative array containing the type and length
*/
function PMA_extract_type_length($fieldspec) {
$first_bracket_pos = strpos($fieldspec, '(');
if ($first_bracket_pos) {
$length = chop(substr($fieldspec, $first_bracket_pos + 1, (strpos($fieldspec, ')') - $first_bracket_pos - 1)));
$type = chop(substr($fieldspec, 0, $first_bracket_pos));
} else {
$type = $fieldspec;
$length = '';
}
return array(
'type' => $type,
'length' => $length
);
}
?>

View File

@@ -1339,12 +1339,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// loic1: displays special characters from binaries
$field_flags = PMA_DBI_field_flags($dt_result, $i);
if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
$db_value = $row[$i];
$row[$i] = '';
for ($j = 0; $j < ceil($meta->length / 8); $j++) {
$row[$i] .= sprintf('%08d', decbin(ord(substr($db_value, $j, 1))));
}
$row[$i] = substr($row[$i], -$meta->length);
$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]);

View File

@@ -191,6 +191,11 @@ for ($i = 0; $i <= $num_fields; $i++) {
$row = $fields_meta[$i];
}
$type_and_length = PMA_extract_type_length($row['Type']);
if ($type_and_length['type'] == 'bit') {
$row['Default'] = PMA_printable_bit_value($row['Default'], $type_and_length['length']);
}
// Cell index: If certain fields get left out, the counter shouldn't chage.
$ci = 0;
// Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
@@ -227,12 +232,10 @@ for ($i = 0; $i <= $num_fields; $i++) {
$type = preg_replace('@ZEROFILL@i', '', $type);
$type = preg_replace('@UNSIGNED@i', '', $type);
if (strpos($type, '(')) {
$length = chop(substr($type, (strpos($type, '(') + 1), (strpos($type, ')') - strpos($type, '(') - 1)));
$type = chop(substr($type, 0, strpos($type, '(')));
} else {
$length = '';
}
$type_and_length = PMA_extract_type_length($type);
$type = $type_and_length['type'];
$length = $type_and_length['length'];
unset($type_and_length);
} // end if else
// some types, for example longtext, are reported as

View File

@@ -424,11 +424,7 @@ foreach ($rows as $row_id => $vrow) {
$special_chars = '';
$data = $vrow[$field['Field']];
} elseif ($field['True_Type'] == 'bit') {
$special_chars = '';
for ($j = 0; $j < ceil($field['len'] / 8); $j++) {
$special_chars .= sprintf('%08d', decbin(ord(substr($vrow[$field['Field']], $j, 1))));
}
$special_chars = substr($special_chars, -$field['len']);
$special_chars = PMA_printable_bit_value($vrow[$field], $len);
} else {
// loic1: special binary "characters"
if ($field['is_binary'] || $field['is_blob']) {
@@ -457,7 +453,11 @@ foreach ($rows as $row_id => $vrow) {
} else {
$data = $field['Default'];
}
$special_chars = htmlspecialchars($field['Default']);
if ($field['True_Type'] == 'bit') {
$special_chars = PMA_printable_bit_value($field['Default'], $len);
} else {
$special_chars = htmlspecialchars($field['Default']);
}
$backup_field = '';
}

View File

@@ -212,6 +212,8 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
$aryFields[] = $row['Field'];
$type = $row['Type'];
$type_and_length = PMA_extract_type_length($row['Type']);
// reformat mysql query output - staybyte - 9. June 2001
// loic1: set or enum types: slashes single quotes inside options
if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
@@ -335,7 +337,14 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
<td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
<td nowrap="nowrap" style="font-size: 70%"><?php echo $attribute; ?></td>
<td><?php echo (($row['Null'] == 'YES') ? $strYes : $strNo); ?></td>
<td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
<td nowrap="nowrap"><?php
if (isset($row['Default'])) {
if ($type_and_length['type'] == 'bit') {
echo PMA_printable_bit_value($row['Default'], $type_and_length['length']);
} else {
echo $row['Default'];
}
} ?></td>
<td nowrap="nowrap"><?php echo $row['Extra']; ?></td>
<td align="center">
<a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT COUNT(*) AS ' . PMA_backquote($strRows) . ', ' . PMA_backquote($row['Field']) . ' FROM ' . PMA_backquote($table) . ' GROUP BY ' . PMA_backquote($row['Field']) . ' ORDER BY ' . PMA_backquote($row['Field'])); ?>">