TSV export and import (bug #3097657)

This commit is contained in:
Jakub Vrana 2010-10-29 18:02:20 +02:00
parent 772f71a780
commit e225d22f97
5 changed files with 8 additions and 7 deletions

View file

@ -494,7 +494,7 @@ document.getElementById('username').focus();
* @return array
*/
function dumpFormat() {
return array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;');
return array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
}
/** Export table structure

View file

@ -697,11 +697,11 @@ function search_tables() {
*/
function dump_csv($row) {
foreach ($row as $key => $val) {
if (preg_match("~[\"\n,;]~", $val) || $val === "") {
if (preg_match("~[\"\n,;\t]~", $val) || $val === "") {
$row[$key] = '"' . str_replace('"', '""', $val) . '"';
}
}
echo implode(($_POST["format"] == "csv" ? "," : ";"), $row) . "\n";
echo implode(($_POST["format"] == "csv" ? "," : ($_POST["format"] == "tsv" ? "\t" : ";")), $row) . "\n";
}
/** Apply SQL function

View file

@ -45,7 +45,7 @@ if ($_POST && !$error) {
if ($_POST["export"]) {
$adminer->dumpHeaders($TABLE);
$adminer->dumpTable($TABLE, "");
if (ereg("csv", $_POST["format"])) {
if (ereg("csv|tsv", $_POST["format"])) {
$row = array_keys($fields);
if ($select) {
$row = array();
@ -143,7 +143,7 @@ if ($_POST && !$error) {
preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
$affected = count($matches[0]);
begin();
$separator = ($_POST["separator"] == "csv" ? "," : ";");
$separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";"));
foreach ($matches[0] as $key => $val) {
preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
@ -396,7 +396,7 @@ if (!$columns) {
}
print_fieldset("import", lang('CSV Import'), !$rows);
echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> ";
echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;"), $adminer_export["format"], 1); // 1 - select
echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_export["format"], 1); // 1 - select
echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n";
echo "</div></fieldset>\n";

View file

@ -1,5 +1,6 @@
Adminer 3.1.0-dev:
Customizable export
TSV export and import
Support for virtual foreign keys
Option to show only errors in SQL command
Link to bookmark SQL command

View file

@ -439,7 +439,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
function dumpFormat() {
return array('csv' => 'CSV,', 'csv;' => 'CSV;');
return array('csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
}
function dumpTable() {