Browse files

TSV export and import (bug #3097657)

  • Loading branch information...
1 parent 772f71a commit e225d22f9731661ffcc882fe0ba374a395c95c12 @vrana committed Oct 29, 2010
View
2 adminer/include/adminer.inc.php
@@ -494,7 +494,7 @@ function dumpOutput() {
* @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
4 adminer/include/functions.inc.php
@@ -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
6 adminer/select.inc.php
@@ -45,7 +45,7 @@
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 @@
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 @@
}
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
1 changes.txt
@@ -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
2 editor/include/adminer.inc.php
@@ -439,7 +439,7 @@ function dumpOutput() {
}
function dumpFormat() {
- return array('csv' => 'CSV,', 'csv;' => 'CSV;');
+ return array('csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
}
function dumpTable() {

0 comments on commit e225d22

Please sign in to comment.