null value checkbox
This commit is contained in:
@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
|
||||
$Id$
|
||||
$Source$
|
||||
|
||||
2001-12-29 Marc Delisle <lem9@users.sourceforge.net>
|
||||
* tbl_change.php3, tbl_replace.php3, Documentation.html:
|
||||
feature 442855: checkboxes for null values,
|
||||
modifications by Marc and Lo<4C>c
|
||||
|
||||
2001-12-29 Lo<4C>c Chapeaux <lolo@phpheaven.net>
|
||||
* header.inc.php3, lines 60-62; libraries/defines.lib.php3, lines 102-103;
|
||||
libraries/common.lib.php3, lines 672-678: patch #497632 - Support for
|
||||
|
@@ -1209,8 +1209,9 @@
|
||||
<p>
|
||||
<b>How can I insert a null value into my table?</b>
|
||||
<br />
|
||||
Enter "null", without the quotes, as the field's value. This is
|
||||
especially useful for <tt>Timestamp</tt> or <tt>AutoIncrement</tt> fields.
|
||||
Since version 2.2.3, you have a checkbox for each field that can be null.
|
||||
Before 2.2.3, you had to enter "null", without the quotes,
|
||||
as the field's value.
|
||||
</p>
|
||||
|
||||
<h3>[phpMyAdmin project]</h3>
|
||||
|
103
tbl_change.php3
103
tbl_change.php3
@@ -116,7 +116,7 @@ else
|
||||
?>
|
||||
|
||||
<!-- Change table properties form -->
|
||||
<form method="post" action="tbl_replace.php3">
|
||||
<form method="post" action="tbl_replace.php3" name="insertForm">
|
||||
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
|
||||
<input type="hidden" name="server" value="<?php echo $server; ?>" />
|
||||
<input type="hidden" name="db" value="<?php echo $db; ?>" />
|
||||
@@ -142,6 +142,7 @@ echo "\n";
|
||||
<th><?php echo $strField; ?></th>
|
||||
<th><?php echo $strType; ?></th>
|
||||
<th><?php echo $strFunction; ?></th>
|
||||
<th><?php echo $strNull; ?></th>
|
||||
<th><?php echo $strValue; ?></th>
|
||||
</tr>
|
||||
|
||||
@@ -201,34 +202,40 @@ for ($i = 0; $i < $fields_cnt; $i++) {
|
||||
if (isset($row)) {
|
||||
// loic1: null field value
|
||||
if (!isset($row[$field])) {
|
||||
$row[$field] = 'NULL';
|
||||
}
|
||||
// loic1: special binary "characters"
|
||||
else if ($is_binary || $is_blob) {
|
||||
$row[$field] = str_replace("\x00", '\0', $row[$field]);
|
||||
$row[$field] = str_replace("\x08", '\b', $row[$field]);
|
||||
$row[$field] = str_replace("\x0a", '\n', $row[$field]);
|
||||
$row[$field] = str_replace("\x0d", '\r', $row[$field]);
|
||||
$row[$field] = str_replace("\x1a", '\Z', $row[$field]);
|
||||
} // end if
|
||||
$special_chars = htmlspecialchars($row[$field]);
|
||||
$data = $row[$field];
|
||||
$row[$field] = 'NULL';
|
||||
$special_chars = '';
|
||||
$data = $row[$field];
|
||||
} else {
|
||||
// loic1: special binary "characters"
|
||||
if ($is_binary || $is_blob) {
|
||||
$row[$field] = str_replace("\x00", '\0', $row[$field]);
|
||||
$row[$field] = str_replace("\x08", '\b', $row[$field]);
|
||||
$row[$field] = str_replace("\x0a", '\n', $row[$field]);
|
||||
$row[$field] = str_replace("\x0d", '\r', $row[$field]);
|
||||
$row[$field] = str_replace("\x1a", '\Z', $row[$field]);
|
||||
} // end if
|
||||
$special_chars = htmlspecialchars($row[$field]);
|
||||
$data = $row[$field];
|
||||
} // end if... else...
|
||||
// loic1: if a timestamp field value is not included in an update
|
||||
// statement MySQL auto-update it to the current timestamp
|
||||
$backup_field = ($row_table_def['True_Type'] == 'timestamp')
|
||||
? ''
|
||||
: '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($data) . '" />';
|
||||
: '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$field]) . '" />';
|
||||
} else {
|
||||
// loic1: display default values
|
||||
if (!isset($row_table_def['Default'])) {
|
||||
$row_table_def['Default'] = (($row_table_def['Null'] == 'YES') ? 'NULL' : '');
|
||||
$row_table_def['Default'] = '';
|
||||
$data = 'NULL';
|
||||
} else {
|
||||
$data = $row_table_def['Default'];
|
||||
}
|
||||
$special_chars = htmlspecialchars($row_table_def['Default']);
|
||||
$data = $row_table_def['Default'];
|
||||
$backup_field = '';
|
||||
}
|
||||
|
||||
// The function column
|
||||
// -------------------
|
||||
// Change by Bernard M. Piller <bernard@bmpsystems.com>
|
||||
// We don't want binary data to be destroyed
|
||||
// Note: from the MySQL manual: "BINARY doesn't affect how the column is
|
||||
@@ -271,7 +278,23 @@ for ($i = 0; $i < $fields_cnt; $i++) {
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
// The null column
|
||||
// ---------------
|
||||
echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
|
||||
if ($row_table_def['Null'] == 'YES') {
|
||||
echo ' <input type="checkbox"'
|
||||
. ' name="fields_null[' . urlencode($field) . ']"';
|
||||
if ($data == 'NULL') {
|
||||
echo ' checked="checked"';
|
||||
}
|
||||
echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'fields[' . urlencode($field) . ']\'].value = \'\'}; return true" />' . "\n";
|
||||
} else {
|
||||
echo ' ' . "\n";
|
||||
}
|
||||
echo ' </td>' . "\n";
|
||||
|
||||
// The value column (depends on type)
|
||||
// ----------------
|
||||
if (strstr($row_table_def['True_Type'], 'text')) {
|
||||
?>
|
||||
<td bgcolor="<?php echo $bgcolor; ?>">
|
||||
@@ -289,7 +312,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
|
||||
$enum = ereg_replace('\\)$', '', $enum);
|
||||
$enum = explode('\',\'', substr($enum, 1, -1));
|
||||
$enum_cnt = count($enum);
|
||||
$seenchecked = 0;
|
||||
// $seenchecked = 0;
|
||||
?>
|
||||
<td bgcolor="<?php echo $bgcolor; ?>">
|
||||
<input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="$enum$" />
|
||||
@@ -313,23 +336,21 @@ for ($i = 0; $i < $fields_cnt; $i++) {
|
||||
if ($data == $enum_atom
|
||||
|| ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
|
||||
&& isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
|
||||
// To be able to select the [Null] value when the field is
|
||||
// null, we lose the ability to select besides the default
|
||||
// value
|
||||
echo ' selected="selected"';
|
||||
$seenchecked = 1;
|
||||
// $seenchecked = 1;
|
||||
}
|
||||
echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
|
||||
} // end for
|
||||
|
||||
if ($row_table_def['Null'] == 'YES') {
|
||||
echo ' ';
|
||||
echo '<option value="null"';
|
||||
if ($seenchecked == 0) {
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>[' . $strNull . ']</option>' . "\n";
|
||||
} // end if
|
||||
// old null option
|
||||
// if ($row_table_def['Null'] == 'YES') {
|
||||
// echo ' ';
|
||||
// echo '<option value="null"';
|
||||
// if ($seenchecked == 0) {
|
||||
// echo ' selected="selected"';
|
||||
// }
|
||||
// echo '>[' . $strNull . ']</option>' . "\n";
|
||||
// } // end if
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
@@ -344,25 +365,23 @@ for ($i = 0; $i < $fields_cnt; $i++) {
|
||||
if ($data == $enum_atom
|
||||
|| ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
|
||||
&& isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
|
||||
// To be able to display a checkmark in the [Null] box when
|
||||
// the field is null, we lose the ability to display a
|
||||
// checkmark besides the default value
|
||||
echo ' checked="checked"';
|
||||
$seenchecked = 1;
|
||||
// $seenchecked = 1;
|
||||
}
|
||||
echo ' />' . "\n";
|
||||
echo ' ' . htmlspecialchars($enum_atom) . "\n";
|
||||
} // end for
|
||||
|
||||
if ($row_table_def['Null'] == 'YES') {
|
||||
echo ' ';
|
||||
echo '<input type="radio" name="field_' . md5($field) . '[]" value="null"';
|
||||
if ($seenchecked == 0) {
|
||||
echo ' checked="checked"';
|
||||
}
|
||||
echo ' />' . "\n";
|
||||
echo ' [' . $strNull . ']' . "\n";
|
||||
} // end if
|
||||
// old null option
|
||||
// if ($row_table_def['Null'] == 'YES') {
|
||||
// echo ' ';
|
||||
// echo '<input type="radio" name="field_' . md5($field) . '[]" value="null"';
|
||||
// if ($seenchecked == 0) {
|
||||
// echo ' checked="checked"';
|
||||
// }
|
||||
// echo ' />' . "\n";
|
||||
// echo ' [' . $strNull . ']' . "\n";
|
||||
// } // end if
|
||||
} // end else
|
||||
echo "\n";
|
||||
?>
|
||||
|
@@ -105,6 +105,11 @@ if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
// Was the Null checkbox checked for this field?
|
||||
if (isset($fields_null) && isset($fields_null[$encoded_key])) {
|
||||
$val = 'NULL';
|
||||
}
|
||||
|
||||
// No change for this column and no MySQL function is used -> next column
|
||||
if (empty($funcs[$encoded_key])
|
||||
&& isset($fields_prev) && isset($fields_prev[$encoded_key])
|
||||
@@ -154,7 +159,7 @@ else {
|
||||
while (list($key, $val) = each($fields)) {
|
||||
$encoded_key = $key;
|
||||
$key = urldecode($key);
|
||||
$fieldlist .= PMA_backquote($key) . ', ';
|
||||
$fieldlist .= PMA_backquote($key) . ', ';
|
||||
|
||||
switch (strtolower($val)) {
|
||||
case 'null':
|
||||
@@ -192,6 +197,11 @@ else {
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
// Was the Null checkbox checked for this field?
|
||||
if (isset($fields_null) && isset($fields_null[$encoded_key])) {
|
||||
$val = 'NULL';
|
||||
}
|
||||
|
||||
if (empty($funcs[$encoded_key])) {
|
||||
$valuelist .= $val . ', ';
|
||||
} else if ($val == '\'\''
|
||||
|
Reference in New Issue
Block a user