]> git.joonet.de Git - adminer.git/commitdiff
TSV export and import (bug #3097657)
authorJakub Vrana <jakub@vrana.cz>
Fri, 29 Oct 2010 16:02:20 +0000 (18:02 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 29 Oct 2010 16:02:20 +0000 (18:02 +0200)
adminer/include/adminer.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
changes.txt
editor/include/adminer.inc.php

index 322f800ae67042e5e44b855c5b284ff503a1b72b..d724f274513fe9f8d6e0122bd57f997037055a1c 100644 (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
index 1d9c186086ddab6937e48ffab18ed870a6e3d3d1..3d289f5fb9ebd9330c1fced8b4b311b8fb900481 100644 (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
index 9d4b5ad22f50b1b6caf2fbeb9a89e7aa1e28d640..433879354364ac328a790638dd53b732c81ab11e 100644 (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";
                
index 356b0782ad98b504a8530c639b93295bfe1fe140..3e34d28f5fb646442eeed02068b9e5c668aad0ff 100644 (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
index e1480f11d406f4d9ff7fd9a2c4b62e4eb4dd3d40..ba76c8602d756c66853c893581cc7ca530ce1113 100644 (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() {