From 7541ceb1ca9d4b3b70a6931281c2954ad918d157 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 26 Apr 2013 22:57:44 -0700 Subject: [PATCH] Improve export of binary data types (bug #3526494) --- adminer/dump.inc.php | 3 ++- adminer/include/adminer.inc.php | 6 ++++-- adminer/include/functions.inc.php | 20 ++++++++++++++++++++ adminer/select.inc.php | 16 +++------------- changes.txt | 1 + 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 3d9f0bcd..8b2dc486 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -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"; diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 615d92cc..b88b648c 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -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" ); } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 3d65f0fa..ade083f3 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -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 diff --git a/adminer/select.inc.php b/adminer/select.inc.php index a249bc2d..4ef073fd 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -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()) { diff --git a/changes.txt b/changes.txt index 3ed6d05f..c24b7e58 100644 --- a/changes.txt +++ b/changes.txt @@ -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