patch 612202 null for foreign keys

This commit is contained in:
Marc Delisle
2002-09-20 21:13:17 +00:00
parent 986135ea26
commit d6ec7e3f24
4 changed files with 34 additions and 9 deletions

View File

@@ -8,6 +8,8 @@ $Source$
2002-09-20 Marc Delisle <lem9@users.sourceforge.net>
* libraries/display_tbl.lib.php3: bug 612117, vertical view and
buttons as links
* libraries/tbl_change.js, tbl_change.php3, tbl_replace.php3:
patch 612202: NULL for foreign keys, thanks to Markus L. Noga
2002-09-19 Marc Delisle <lem9@users.sourceforge.net>
* libraries/sqlparser.lib.php3: bug 608459: syntax coloring and

View File

@@ -18,8 +18,9 @@ function nullify(theType, urlField, md5Field)
rowForm.elements['funcs[' + urlField + ']'].selectedIndex = -1;
}
// "SET" field or "ENUM" field with more than 20 characters
if (theType == 1 || theType == 3) {
// "SET" field , "ENUM" field with more than 20 characters
// or foreign key field
if (theType == 1 || theType == 3 || theType == 4) {
rowForm.elements['field_' + md5Field + '[]'].selectedIndex = -1;
}
// Other "ENUM" field
@@ -31,7 +32,7 @@ function nullify(theType, urlField, md5Field)
} // end for
}
// Other field types
else /*if (theType == 4)*/ {
else /*if (theType == 5)*/ {
rowForm.elements['fields[' + urlField + ']'].value = '';
} // end if... else if... else

View File

@@ -377,8 +377,10 @@ for ($i = 0; $i < $fields_cnt; $i++) {
}
} else if (strstr($row_table_def['True_Type'], 'set')) {
$onclick .= '3, ';
} else {
} else if ($foreigners && isset($foreigners[$field])) {
$onclick .= '4, ';
} else {
$onclick .= '5, ';
}
$onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n";
echo $onclick;
@@ -418,19 +420,25 @@ for ($i = 0; $i < $fields_cnt; $i++) {
$foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);
$dispsql = 'SELECT ' . PMA_backquote($foreign_field)
. (($foreign_display == FALSE) ? '' : ', ' . PMA_backquote($foreign_display))
. ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table);
. ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table)
. ' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display);
$disp = PMA_mysql_query($dispsql);
}
} // end if $foreigners
if (isset($disp) && $disp) {
echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
echo ' ' . $backup_field . "\n";
echo ' <select name="fields[' . urlencode($field) . ']">' . "\n";
?>
<td bgcolor="<?php echo $bgcolor; ?>">
<?php echo $backup_field . "\n"; ?>
<input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="$foreign$" tabindex="<?php echo $i+1; ?>" />
<select name="field_<?php echo md5($field); ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i+1; ?>">
<option value=""></option>
<?php
while ($relrow = @PMA_mysql_fetch_array($disp)) {
$key = $relrow[$foreign_field];
$value = (($foreign_display != FALSE) ? '&nbsp;-&nbsp;' . htmlspecialchars($relrow[$foreign_display]) : '');
echo ' <option value="' . htmlspecialchars($key) . '"';
echo ' <option value="' . htmlspecialchars($key) . '"';
if ($key == $data) {
echo ' selected="selected"';
} // end if

View File

@@ -118,6 +118,20 @@ if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
$val = "''";
}
break;
case '$foreign$':
// if we have a foreign key, then construct the value
$f = 'field_' . md5($key);
if (!empty($$f)) {
$val = implode(',', $$f);
if ($val == 'null') {
// void
} else {
$val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
}
} else {
$val = "''";
}
break;
default:
if (get_magic_quotes_gpc()) {
$val = "'" . str_replace('\\"', '"', $val) . "'";