]> git.joonet.de Git - adminer.git/commitdiff
Improve export of binary data types (bug #3526494)
authorJakub Vrana <jakub@vrana.cz>
Sat, 27 Apr 2013 05:57:44 +0000 (22:57 -0700)
committerJakub Vrana <jakub@vrana.cz>
Sat, 27 Apr 2013 05:57:44 +0000 (22:57 -0700)
adminer/dump.inc.php
adminer/include/adminer.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
changes.txt

index 3d9f0bcd7f7ab1b74e9952b362d8835d734bfb72..8b2dc4864c786a89f86d3660c6f60dc8193e4ada 100644 (file)
@@ -76,7 +76,8 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
                                                        }
                                                        $adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""));
                                                        if ($data) {
-                                                               $adminer->dumpData($name, $_POST["data_style"], "SELECT * FROM " . table($name));
+                                                               $fields = fields($name);
+                                                               $adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
                                                        }
                                                        if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) {
                                                                echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
index 615d92ccf76d390bb3b63bfcc3a2107d5bb7ff00..b88b648c1eb6c03cbd1becbd0072b5950d6aa5cc 100644 (file)
@@ -638,7 +638,8 @@ username.form['auth[driver]'].onchange();
                                $buffer = "";
                                $keys = array();
                                $suffix = "";
-                               while ($row = $result->fetch_row()) {
+                               $fetch_function = ($table != '' ? 'fetch_assoc' : 'fetch_row');
+                               while ($row = $result->$fetch_function()) {
                                        if (!$keys) {
                                                $values = array();
                                                foreach ($row as $val) {
@@ -660,8 +661,9 @@ username.form['auth[driver]'].onchange();
                                                        $insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', $keys)) . ") VALUES";
                                                }
                                                foreach ($row as $key => $val) {
+                                                       $field = $fields[$key];
                                                        $row[$key] = ($val !== null
-                                                               ? (ereg('(^|[^o])int|float|double|decimal|bit', $fields[$keys[$key]]["type"]) && $val != '' ? $val : q($val)) //! columns looking like functions
+                                                               ? unconvert_field($field, ereg('(^|[^o])int|float|double|decimal', $field["type"]) && $val != '' ? $val : q($val))
                                                                : "NULL"
                                                        );
                                                }
index 3d65f0fa6e2c8606a0d53999275038188f12a43f..ade083f3923d9b8d0061c2f1525be8f43be4b7b6 100644 (file)
@@ -370,6 +370,26 @@ function where_link($i, $column, $value, $operator = "=") {
        return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=" . urlencode(($value !== null ? $operator : "IS NULL")) . "&where%5B$i%5D%5Bval%5D=" . urlencode($value);
 }
 
+/** Get select clause for convertible fields
+* @param array
+* @param array
+* @param array
+* @return string
+*/
+function convert_fields($columns, $fields, $select = array()) {
+       $return = "";
+       foreach ($columns as $key => $val) {
+               if ($select && !in_array(idf_escape($key), $select)) {
+                       continue;
+               }
+               $as = convert_field($fields[$key]);
+               if ($as) {
+                       $return .= ", $as AS " . idf_escape($key);
+               }
+       }
+       return $return;
+}
+
 /** Set cookie valid for 1 month
 * @param string
 * @param string
index a249bc2d6a804b266f7cdee0f3c1ea0ea45a40c7..4ef073fd58b3f22935d27adc942122362e8378f6 100644 (file)
@@ -30,19 +30,9 @@ $is_group = count($group) < count($select);
 $where = $adminer->selectSearchProcess($fields, $indexes);
 $order = $adminer->selectOrderProcess($fields, $indexes);
 $limit = $adminer->selectLimitProcess();
-$from = ($select ? implode(", ", $select) : "*" . ($oid ? ", $oid" : ""));
-if ($jush == "sql" && !$_POST["export"]) {
-       foreach ($columns as $key => $val) {
-               if ($select && !in_array(idf_escape($key), $select)) {
-                       continue;
-               }
-               $as = convert_field($fields[$key]);
-               if ($as) {
-                       $from .= ", $as AS " . idf_escape($key);
-               }
-       }
-}
-$from .= "\nFROM " . table($TABLE);
+$from = ($select ? implode(", ", $select) : "*" . ($oid ? ", $oid" : ""))
+       . convert_fields($columns, $fields, $select)
+       . "\nFROM " . table($TABLE);
 $group_by = ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
 
 if ($_GET["val"] && is_ajax()) {
index 3ed6d05f11f25180feb295f01b6de4c239a4adc3..c24b7e5879b5824100ce71588305a05837122a74 100644 (file)
@@ -4,6 +4,7 @@ Print run time next to executed queries
 Disable SQL export when applying functions in select
 MySQL: Optimize create table page and Editor navigation
 MySQL: Display bit type as binary number
+MySQL: Improve export of binary data types
 MySQL: Fix handling of POINT data type (bug #3582578)
 MySQL: Don't export binary and geometry columns twice in select