diff --git a/ChangeLog b/ChangeLog index fd7248ddf..523028acb 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-05-05 Michal Cihar + * 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 * libraries/sqlparser.data.php: Add ENGINE to reserved words (used instead of TYPE in MySQL 4.1.1). diff --git a/config.inc.php b/config.inc.php index 3e35c00f3..4579373f2 100644 --- a/config.inc.php +++ b/config.inc.php @@ -260,6 +260,7 @@ $cfg['CharEditing'] = 'input'; // Which editor should be used for CHAR/VARCHAR fields: // input - allows limiting of input length // textarea - allows newlines in fields +$cfg['InsertRows'] = 2; // How many rows can be inserted at one time // For the export features... $cfg['ZipDump'] = TRUE; // Allow the use of zip/gzip/bzip diff --git a/libraries/common.lib.php b/libraries/common.lib.php index f9c1e81df..ec781a231 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -136,7 +136,7 @@ if (isset($cfg['FileRevision'])) { } else { $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'); } diff --git a/libraries/config_import.lib.php b/libraries/config_import.lib.php index 0b8355981..33ed337d2 100644 --- a/libraries/config_import.lib.php +++ b/libraries/config_import.lib.php @@ -466,6 +466,10 @@ if (!isset($cfg['CharEditing'])) { $cfg['CharEditing'] = 'input'; } +if (!isset($cfg['InsertRows'])) { + $cfg['InsertRows'] = 2; +} + if (!isset($cfg['ZipDump'])) { if (isset($cfgZipDump)) { $cfg['ZipDump'] = $cfgZipDump; diff --git a/tbl_change.php b/tbl_change.php index 72ef9bbdd..73ada4202 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -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 // if we set a value in some field $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)) { $trow_table_def[] = $trow; @@ -215,7 +220,19 @@ foreach($loop_array AS $vrowcount => $vrow) { unset($vrow); } + if ($insert_mode) { + $vkey = '[multi_edit][' . $vrowcount . ']'; + $browse_foreigners_uri = ''; + } else { + $vkey = '[multi_edit][' . urlencode($primary_keys[$vrowcount]) . ']'; + $browse_foreigners_uri = '&pk=' . urlencode($primary_keys[$vrowcount]); + } + $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result); + if ($insert_mode && $vrowcount > 0) { + echo ''; + echo '
' . "\n"; + } ?> @@ -231,14 +248,6 @@ foreach($loop_array AS $vrowcount => $vrow) { (isset($primary_key) ? $primary_key : null))); - $query = array(); $message = ''; 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 = ''; $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_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_funcs = (isset($funcs['multi_edit']) && isset($funcs['multi_edit'][$enc_primary_key]) ? $funcs['multi_edit'][$enc_primary_key] : (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_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)); - - // 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); - } + $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'][$i]) ? $fields_prev['multi_edit'][$i] : (isset($fields_prev) ? $fields_prev : 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'][$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'][$i]) ? $fields_null['multi_edit'][$i] : (isset($fields_null) ? $fields_null : null)); foreach($me_fields AS $key => $val) { $encoded_key = $key; @@ -202,11 +199,15 @@ else { } // end while // 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); - $query[] = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')'; + $query[0] .= '(' . $valuelist . '), '; $message = $strInsertedRows . ' '; } + $query[0] = preg_replace('@, $@', '', $query[0]); } // end row insertion