]> git.joonet.de Git - adminer.git/commitdiff
Simplify dumpOutput, dumpFormat and dumpData methods
authorJakub Vrana <jakub@vrana.cz>
Fri, 29 Oct 2010 15:11:00 +0000 (17:11 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 29 Oct 2010 15:23:03 +0000 (17:23 +0200)
adminer/dump.inc.php
adminer/include/adminer.inc.php
adminer/select.inc.php
editor/include/adminer.inc.php

index e53885514deb427431448716821481ddbbc3f519..fb9f5188ac679b42cbc28147b31d3bf84fbec0bd 100644 (file)
@@ -75,7 +75,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
                                                        }
                                                        $adminer->dumpTable($row["Name"], ($table ? $_POST["table_style"] : ""));
                                                        if ($data) {
-                                                               $adminer->dumpData($row["Name"], $_POST["data_style"]);
+                                                               $adminer->dumpData($row["Name"], $_POST["data_style"], "SELECT * FROM " . table($row["Name"]));
                                                        }
                                                        if ($is_sql && $_POST["triggers"]) {
                                                                $triggers = trigger_sql($row["Name"], $_POST["table_style"]);
@@ -167,8 +167,8 @@ if (!$row) {
        $row = array("output" => "text", "format" => "sql", "db_style" => (DB != "" ? "" : "CREATE"), "table_style" => "DROP+CREATE", "data_style" => "INSERT");
 }
 $checked = ($_GET["dump"] == "");
-echo "<tr><th>" . lang('Output') . "<td>" . $adminer->dumpOutput(0, $row["output"]) . "\n";
-echo "<tr><th>" . lang('Format') . "<td>" . $adminer->dumpFormat(0, $row["format"]) . "\n";
+echo "<tr><th>" . lang('Output') . "<td>" . html_select("output", $adminer->dumpOutput(), $row["output"], 0) . "\n"; // 0 - radio
+echo "<tr><th>" . lang('Format') . "<td>" . html_select("format", $adminer->dumpFormat(), $row["format"], 0) . "\n"; // 0 - radio
 echo ($jush == "sqlite" ? "" : "<tr><th>" . lang('Database') . "<td>" . html_select('db_style', $db_style, $row["db_style"])
        . (support("routine") ? checkbox("routines", 1, $checked, lang('Routines')) : "")
        . (support("event") ? checkbox("events", 1, $checked, lang('Events')) : "")
index 9973c13fc4f43906004aba1f497a57d4bba34e69..fb700597082fe760e45e76a02e094e492dcfaf9b 100644 (file)
@@ -476,11 +476,9 @@ document.getElementById('username').focus();
        }
        
        /** Returns export output options
-       * @param bool generate select (otherwise radio)
-       * @param string
-       * @return string
+       * @return array
        */
-       function dumpOutput($select, $value = "") {
+       function dumpOutput() {
                $return = array('text' => lang('open'), 'file' => lang('save'));
                if (function_exists('gzencode')) {
                        $return['gz'] = 'gzip';
@@ -489,16 +487,14 @@ document.getElementById('username').focus();
                        $return['bz2'] = 'bzip2';
                }
                // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
-               return html_select("output", $return, $value, $select);
+               return $return;
        }
        
        /** Returns export format options
-       * @param bool generate select (otherwise radio)
-       * @param string
-       * @return string
+       * @return array
        */
-       function dumpFormat($select, $value = "") {
-               return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select);
+       function dumpFormat() {
+               return array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;');
        }
        
        /** Export table structure
@@ -602,10 +598,10 @@ DROP PROCEDURE adminer_alter;
        /** Export table data
        * @param string
        * @param string
-       * @param string query to execute, defaults to SELECT * FROM $table
+       * @param string
        * @return null prints data
        */
-       function dumpData($table, $style, $select = "") {
+       function dumpData($table, $style, $query) {
                global $connection, $jush;
                $max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
                if ($style) {
@@ -613,7 +609,7 @@ DROP PROCEDURE adminer_alter;
                                echo truncate_sql($table) . ";\n";
                        }
                        $fields = fields($table);
-                       $result = $connection->query(($select ? $select : "SELECT * FROM " . table($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
+                       $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
                        if ($result) {
                                $insert = "";
                                $buffer = "";
index b4ec236cc68370ac91217f3d40273d5712c27d68..3c10e8446aef4884b8076bf88dab18bcafdeb2c5 100644 (file)
@@ -389,7 +389,8 @@ if (!$columns) {
 <?php
                        }
                        print_fieldset("export", lang('Export'));
-                       echo $adminer->dumpOutput(1, $adminer_export["output"]) . " " . $adminer->dumpFormat(1, $adminer_export["format"]); // 1 - select
+                       $output = $adminer->dumpOutput();
+                       echo ($output ? html_select("output", $output, $adminer_export["output"]) . " " : "") . html_select("format", $adminer->dumpFormat(), $adminer_export["format"]);
                        echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
                        echo "</div></fieldset>\n";
                }
index 47a86a74dc6756de2256f8a7ff689f6fb05efe29..e1480f11d406f4d9ff7fd9a2c4b62e4eb4dd3d40 100644 (file)
@@ -434,21 +434,21 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                return $return;
        }
        
-       function dumpOutput($select, $value = "") {
-               return "";
+       function dumpOutput() {
+               return array();
        }
        
-       function dumpFormat($select, $value = "") {
-               return html_select("format", array('csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select);
+       function dumpFormat() {
+               return array('csv' => 'CSV,', 'csv;' => 'CSV;');
        }
        
        function dumpTable() {
                echo "\xef\xbb\xbf"; // UTF-8 byte order mark
        }
        
-       function dumpData($table, $style, $select = "") {
+       function dumpData($table, $style, $query) {
                global $connection;
-               $result = $connection->query(($select ? $select : "SELECT * FROM " . idf_escape($table)), 1); // 1 - MYSQLI_USE_RESULT
+               $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT
                if ($result) {
                        while ($row = $result->fetch_assoc()) {
                                dump_csv($row);