Support for insert multiple rows at once (RFE #749733).

This commit is contained in:
Michal Čihař
2004-05-05 10:05:30 +00:00
parent 26f1c83f9a
commit 0b9bdd62a7
6 changed files with 45 additions and 25 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2004-05-05 Michal Cihar <michal@cihar.com>
* config.inc.php, tbl_change.php, tbl_replace.php,
libraries/common.lib.php, libraries/config_import.lib.php: Support for
insert multiple rows at once (RFE #749733).
2004-05-04 Michal Cihar <michal@cihar.com> 2004-05-04 Michal Cihar <michal@cihar.com>
* libraries/sqlparser.data.php: Add ENGINE to reserved words (used instead * libraries/sqlparser.data.php: Add ENGINE to reserved words (used instead
of TYPE in MySQL 4.1.1). of TYPE in MySQL 4.1.1).

View File

@@ -260,6 +260,7 @@ $cfg['CharEditing'] = 'input';
// Which editor should be used for CHAR/VARCHAR fields: // Which editor should be used for CHAR/VARCHAR fields:
// input - allows limiting of input length // input - allows limiting of input length
// textarea - allows newlines in fields // textarea - allows newlines in fields
$cfg['InsertRows'] = 2; // How many rows can be inserted at one time
// For the export features... // For the export features...
$cfg['ZipDump'] = TRUE; // Allow the use of zip/gzip/bzip $cfg['ZipDump'] = TRUE; // Allow the use of zip/gzip/bzip

View File

@@ -136,7 +136,7 @@ if (isset($cfg['FileRevision'])) {
} else { } else {
$cfg['FileRevision'] = array(1, 1); $cfg['FileRevision'] = array(1, 1);
} }
if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 15)) { if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 18)) {
require_once('./libraries/config_import.lib.php'); require_once('./libraries/config_import.lib.php');
} }

View File

@@ -466,6 +466,10 @@ if (!isset($cfg['CharEditing'])) {
$cfg['CharEditing'] = 'input'; $cfg['CharEditing'] = 'input';
} }
if (!isset($cfg['InsertRows'])) {
$cfg['InsertRows'] = 2;
}
if (!isset($cfg['ZipDump'])) { if (!isset($cfg['ZipDump'])) {
if (isset($cfgZipDump)) { if (isset($cfgZipDump)) {
$cfg['ZipDump'] = $cfgZipDump; $cfg['ZipDump'] = $cfgZipDump;

View File

@@ -199,7 +199,12 @@ $fields_cnt = PMA_DBI_num_rows($table_def);
// Set a flag here because the 'if' would not be valid in the loop // Set a flag here because the 'if' would not be valid in the loop
// if we set a value in some field // if we set a value in some field
$insert_mode = (!isset($row) ? TRUE : FALSE); $insert_mode = (!isset($row) ? TRUE : FALSE);
$loop_array = (isset($row) ? $row : array(0 => FALSE)); if ($insert_mode) {
$loop_array = array();
for ($i = 0; $i < $cfg['InsertRows']; $i++) $loop_array[] = FALSE;
} else {
$loop_array = $row;
}
while ($trow = PMA_DBI_fetch_assoc($table_def)) { while ($trow = PMA_DBI_fetch_assoc($table_def)) {
$trow_table_def[] = $trow; $trow_table_def[] = $trow;
@@ -215,7 +220,19 @@ foreach($loop_array AS $vrowcount => $vrow) {
unset($vrow); unset($vrow);
} }
if ($insert_mode) {
$vkey = '[multi_edit][' . $vrowcount . ']';
$browse_foreigners_uri = '';
} else {
$vkey = '[multi_edit][' . urlencode($primary_keys[$vrowcount]) . ']';
$browse_foreigners_uri = '&amp;pk=' . urlencode($primary_keys[$vrowcount]);
}
$vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result); $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
if ($insert_mode && $vrowcount > 0) {
echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '">';
echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
}
?> ?>
<table border="<?php echo $cfg['Border']; ?>"> <table border="<?php echo $cfg['Border']; ?>">
<tr> <tr>
@@ -231,14 +248,6 @@ foreach($loop_array AS $vrowcount => $vrow) {
</tr> </tr>
<?php <?php
if ($insert_mode) {
$vkey = '';
$browse_foreigners_uri = '';
} else {
$vkey = '[multi_edit][' . urlencode($primary_keys[$vrowcount]) . ']';
$browse_foreigners_uri = '&amp;pk=' . urlencode($primary_keys[$vrowcount]);
}
// garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth. // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
$timestamp_seen = 0; $timestamp_seen = 0;
unset($first_timestamp); unset($first_timestamp);

View File

@@ -163,25 +163,22 @@ if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) {
*/ */
else { else {
$loop_array = (isset($primary_key) && is_array($primary_key) ? $primary_key : array(0 => (isset($primary_key) ? $primary_key : null))); $loop_array = (isset($primary_key) && is_array($primary_key) ? $primary_key : array(0 => (isset($primary_key) ? $primary_key : null)));
$query = array();
$message = ''; $message = '';
PMA_DBI_select_db($db); PMA_DBI_select_db($db);
foreach($loop_array AS $primary_key_index => $enc_primary_key) { for ($i = 0; $i < $cfg['InsertRows']; $i++) {
if (!isset($fields['multi_edit'][$i])) break;
if (isset($GLOBALS['insert_ignore_' . $i])) continue;
$enc_primary_key = $i;
$fieldlist = ''; $fieldlist = '';
$valuelist = ''; $valuelist = '';
$me_fields = (isset($fields['multi_edit']) && isset($fields['multi_edit'][$enc_primary_key]) ? $fields['multi_edit'][$enc_primary_key] : (isset($fields) ? $fields : null)); $me_fields = (isset($fields['multi_edit']) && isset($fields['multi_edit'][$i]) ? $fields['multi_edit'][$i] : (isset($fields) ? $fields : null));
$me_fields_prev = (isset($fields_prev['multi_edit']) && isset($fields_prev['multi_edit'][$enc_primary_key]) ? $fields_prev['multi_edit'][$enc_primary_key] : (isset($fields_prev) ? $fields_prev : null)); $me_fields_prev = (isset($fields_prev['multi_edit']) && isset($fields_prev['multi_edit'][$i]) ? $fields_prev['multi_edit'][$i] : (isset($fields_prev) ? $fields_prev : null));
$me_funcs = (isset($funcs['multi_edit']) && isset($funcs['multi_edit'][$enc_primary_key]) ? $funcs['multi_edit'][$enc_primary_key] : (isset($funcs) ? $funcs : null)); $me_funcs = (isset($funcs['multi_edit']) && isset($funcs['multi_edit'][$i]) ? $funcs['multi_edit'][$i] : (isset($funcs) ? $funcs : null));
$me_fields_type = (isset($fields_type['multi_edit']) && isset($fields_type['multi_edit'][$enc_primary_key]) ? $fields_type['multi_edit'][$enc_primary_key] : (isset($fields_type) ? $fields_type : null)); $me_fields_type = (isset($fields_type['multi_edit']) && isset($fields_type['multi_edit'][$i]) ? $fields_type['multi_edit'][$i] : (isset($fields_type) ? $fields_type : null));
$me_fields_null = (isset($fields_null['multi_edit']) && isset($fields_null['multi_edit'][$enc_primary_key]) ? $fields_null['multi_edit'][$enc_primary_key] : (isset($fields_null) ? $fields_null : null)); $me_fields_null = (isset($fields_null['multi_edit']) && isset($fields_null['multi_edit'][$i]) ? $fields_null['multi_edit'][$i] : (isset($fields_null) ? $fields_null : null));
// garvin: Get, if sent, any protected fields to insert them here:
if (isset($me_fields_type) && is_array($me_fields_type) && isset($enc_primary_key)) {
$prot_result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . urldecode($enc_primary_key) . ';');
$prot_row = PMA_DBI_fetch_assoc($prot_result);
}
foreach($me_fields AS $key => $val) { foreach($me_fields AS $key => $val) {
$encoded_key = $key; $encoded_key = $key;
@@ -202,11 +199,15 @@ else {
} // end while } // end while
// Builds the sql insert query // Builds the sql insert query
$fieldlist = preg_replace('@, $@', '', $fieldlist); if (!isset($query)) {
$fieldlist = preg_replace('@, $@', '', $fieldlist);
$query = array('INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES ');
}
$valuelist = preg_replace('@, $@', '', $valuelist); $valuelist = preg_replace('@, $@', '', $valuelist);
$query[] = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')'; $query[0] .= '(' . $valuelist . '), ';
$message = $strInsertedRows . '&nbsp;'; $message = $strInsertedRows . '&nbsp;';
} }
$query[0] = preg_replace('@, $@', '', $query[0]);
} // end row insertion } // end row insertion