diff --git a/ChangeLog b/ChangeLog index 8b4f07d36..20be34ab1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,14 @@ phpMyAdmin - Changelog $Id$ $Source$ +2005-11-23 Michal Čihař + * config.default.php, libraries/import/csv.php, libraries/import/ldi.php: + Drop optional escaping as this should not have any real functionality. + * libraries/import.lib.php: Do not overwrite error message from import in + case of single SQL query is being executed. + * libraries/import/csv.php: Make enclosing behaviour same as in MySQL LOAD + DATA (bug #1363532). + 2005-11-20 Sebastian Mendel * added test/theme.php: for testing themes * phpinfo.php: diff --git a/config.default.php b/config.default.php index e3fd7b2a6..c53abb58a 100644 --- a/config.default.php +++ b/config.default.php @@ -316,14 +316,12 @@ $cfg['Import']['skip_queries'] = '0'; $cfg['Import']['csv_replace'] = FALSE; $cfg['Import']['csv_terminated'] = ';'; $cfg['Import']['csv_enclosed'] = '"'; -$cfg['Import']['csv_enclosed_optionally'] = FALSE; $cfg['Import']['csv_escaped'] = '\\'; $cfg['Import']['csv_new_line'] = 'auto'; $cfg['Import']['csv_columns'] = ''; $cfg['Import']['ldi_replace'] = FALSE; $cfg['Import']['ldi_terminated'] = ';'; $cfg['Import']['ldi_enclosed'] = '"'; -$cfg['Import']['ldi_enclosed_optionally'] = FALSE; $cfg['Import']['ldi_escaped'] = '\\'; $cfg['Import']['ldi_new_line'] = 'auto'; $cfg['Import']['ldi_columns'] = ''; diff --git a/libraries/import.lib.php b/libraries/import.lib.php index b5cc4ee81..683a40253 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -80,7 +80,7 @@ function PMA_importRunQuery($sql = '', $full = '') { $sql_query .= $import_run_buffer['full']; } $executed_queries++; - if ($run_query && $finished && empty($sql) && ( + if ($run_query && $finished && empty($sql) && !$error && ( (!empty($import_run_buffer['sql']) && preg_match('/^[\s]*(SELECT|SHOW)/i', $import_run_buffer['sql'])) || ($executed_queries == 1) )) { diff --git a/libraries/import/csv.php b/libraries/import/csv.php index 394295946..c6af5544b 100644 --- a/libraries/import/csv.php +++ b/libraries/import/csv.php @@ -14,7 +14,6 @@ if ($import_type == 'table') { array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreDuplicates'), array('type' => 'text', 'name' => 'terminated', 'text' => 'strFieldsTerminatedBy', 'size' => 2, 'len' => 1), array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy', 'size' => 2, 'len' => 1), - array('type' => 'bool', 'name' => 'enclosed_optionally', 'text' => 'strEnclosingOptional'), array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy', 'size' => 2, 'len' => 1), array('type' => 'text', 'name' => 'new_line', 'text' => 'strLinesTerminatedBy', 'size' => 2), array('type' => 'text', 'name' => 'columns', 'text' => 'strColumnNames'), @@ -93,10 +92,20 @@ if ($import_type == 'table') { $values = array(); // Grab some SQL queries out of it $i = 0; + $lasti = -1; $finish = FALSE; $ch = $buffer[$i]; while ($i < $len) { + // Deadlock protection + if ($lasti == $i) { + $message = $strInvalidCSVInput; + $show_error_header = TRUE; + $error = TRUE; + break; + } + $lasti = $i; + // Grab empty field if ($ch == $csv_terminated) { $values[] = ''; if ($i == $len - 1) break; @@ -105,28 +114,19 @@ if ($import_type == 'table') { continue; } - // Grab one field - if ($ch == $csv_enclosed || isset($csv_enclosed_optionally)) { - if ($ch == $csv_enclosed) { - $need_end = TRUE; - if ($i == $len - 1) break; - $i++; - $ch = $buffer[$i]; - } else { - $need_end = FALSE; - } - $fail = FALSE; - $value = ''; - while(($need_end && $ch != $csv_enclosed) || (!$need_end && !($ch == $csv_terminated || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))))) { - if ($ch == $csv_escaped) { - if ($i == $len - 1) { - $fail = TRUE; - break; - } - $i++; - $ch = $buffer[$i]; - } - $value .= $ch; + // Grab one field + if ($ch == $csv_enclosed) { + $need_end = TRUE; + if ($i == $len - 1) break; + $i++; + $ch = $buffer[$i]; + } else { + $need_end = FALSE; + } + $fail = FALSE; + $value = ''; + while(($need_end && $ch != $csv_enclosed) || (!$need_end && !($ch == $csv_terminated || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))))) { + if ($ch == $csv_escaped) { if ($i == $len - 1) { $fail = TRUE; break; @@ -134,21 +134,31 @@ if ($import_type == 'table') { $i++; $ch = $buffer[$i]; } - if ($fail) break; - $values[] = $value; - if ($ch == $csv_enclosed) { - if ($i == $len - 1) break; - $i++; - $ch = $buffer[$i]; - } - if ($ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))) { - $finish = TRUE; - } - if ($ch == $csv_terminated) { - if ($i == $len - 1) break; - $i++; - $ch = $buffer[$i]; + $value .= $ch; + if ($i == $len - 1) { + $fail = TRUE; + break; } + $i++; + $ch = $buffer[$i]; + } + if ($fail) break; + $values[] = $value; + // Need to strip trailing enclosing char? + if ($need_end && $ch == $csv_enclosed) { + if ($i == $len - 1) break; + $i++; + $ch = $buffer[$i]; + } + // Are we at the end? + if ($ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))) { + $finish = TRUE; + } + // Go to next char + if ($ch == $csv_terminated) { + if ($i == $len - 1) break; + $i++; + $ch = $buffer[$i]; } // End of line @@ -189,16 +199,16 @@ if ($import_type == 'table') { $buffer = substr($buffer, $i + 1); $len = strlen($buffer); $i = 0; - $ch = $buffer[$i]; + $lasti = -1; + $ch = $buffer[0]; } } // End of parser loop } // End of import loop PMA_importRunQuery(); - if (count($values) != 0) { + if (count($values) != 0 && !$error) { $message = $strInvalidCSVInput; $show_error_header = TRUE; $error = TRUE; - break; } // Commit any possible data in buffers diff --git a/libraries/import/ldi.php b/libraries/import/ldi.php index 404ac293c..257978087 100644 --- a/libraries/import/ldi.php +++ b/libraries/import/ldi.php @@ -33,7 +33,6 @@ if ($import_type == 'table') { array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreDuplicates'), array('type' => 'text', 'name' => 'terminated', 'text' => 'strFieldsTerminatedBy', 'size' => 2, 'len' => 1), array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy', 'size' => 2, 'len' => 1), - array('type' => 'bool', 'name' => 'enclosed_optionally', 'text' => 'strEnclosingOptional'), array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy', 'size' => 2, 'len' => 1), array('type' => 'text', 'name' => 'new_line', 'text' => 'strLinesTerminatedBy', 'size' => 2), array('type' => 'text', 'name' => 'columns', 'text' => 'strColumnNames'), @@ -65,9 +64,6 @@ if ($import_type == 'table') { $sql .= ' FIELDS TERMINATED BY \'' . PMA_sqlAddslashes($ldi_terminated) . '\''; } if (strlen($ldi_enclosed) > 0) { - if (isset($ldi_enclosed_optionally)){ - $sql .= ' OPTIONALLY'; - } $sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\''; } if (strlen($ldi_escaped) > 0) {