Improve CSV; export

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1481 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2010-04-22 23:03:54 +00:00
parent edb6401722
commit acf7a42433
3 changed files with 5 additions and 5 deletions

View file

@ -156,7 +156,7 @@ page_header(lang('Export'), "", ($_GET["export"] != "" ? array("table" => $_GET[
$db_style = array('', 'USE', 'DROP+CREATE', 'CREATE'); $db_style = array('', 'USE', 'DROP+CREATE', 'CREATE');
$table_style = array('', 'DROP+CREATE', 'CREATE'); $table_style = array('', 'DROP+CREATE', 'CREATE');
$data_style = array('', 'TRUNCATE+INSERT', 'INSERT', 'INSERT+UPDATE'); $data_style = array('', 'TRUNCATE+INSERT', 'INSERT', 'INSERT+UPDATE');
if (support("routine")) { if ($driver == "sql") {
$db_style[] = 'CREATE+ALTER'; $db_style[] = 'CREATE+ALTER';
$table_style[] = 'CREATE+ALTER'; $table_style[] = 'CREATE+ALTER';
} }

View file

@ -598,7 +598,7 @@ function dump_csv($row) {
$row[$key] = '"' . str_replace('"', '""', $val) . '"'; $row[$key] = '"' . str_replace('"', '""', $val) . '"';
} }
} }
echo implode(($_POST["format"] == "csv;" ? ";" : ","), $row) . "\n"; echo implode(($_POST["format"] == "csv" ? "," : ";"), $row) . "\n";
} }
/** Apply SQL function /** Apply SQL function

View file

@ -112,7 +112,7 @@ if ($_POST && !$error) {
preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches); preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
$affected = count($matches[0]); $affected = count($matches[0]);
queries("START TRANSACTION"); queries("START TRANSACTION");
$separator = ($_POST["separator"] == ";" ? ";" : ","); $separator = ($_POST["separator"] == "csv" ? "," : ";");
foreach ($matches[0] as $key => $val) { foreach ($matches[0] as $key => $val) {
preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2); preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
@ -132,7 +132,7 @@ if ($_POST && !$error) {
} }
} }
if ($result) { if ($result) {
queries("COMMIT"); queries("COMMIT");
} }
queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result); queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
queries("ROLLBACK"); queries("ROLLBACK");
@ -327,7 +327,7 @@ if (!$columns) {
} }
print_fieldset("import", lang('CSV Import'), !$result->num_rows); print_fieldset("import", lang('CSV Import'), !$result->num_rows);
echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> "; echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> ";
echo html_select("separator", array(",", ";"), ($adminer_export["format"] == "csv;" ? ";" : ","), 1); // 1 - select echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;"), $adminer_export["format"], 1); // 1 - select
echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n"; echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n";
echo "</div></fieldset>\n"; echo "</div></fieldset>\n";