Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MySQL: Support geometry data types

  • Loading branch information...
commit d5400234f065b4c04fefc893a4ffdf8455d91a26 1 parent 31a608e
Jakub Vrána authored
7 adminer/drivers/mssql.inc.php
@@ -591,6 +591,13 @@ function show_status() {
591 591 return array();
592 592 }
593 593
  594 + function convert_field($field) {
  595 + }
  596 +
  597 + function unconvert_field($field, $return) {
  598 + return $return;
  599 + }
  600 +
594 601 function support($feature) {
595 602 return ereg('^(scheme|trigger|view|drop_col)$', $feature); //! routine|
596 603 }
33 adminer/drivers/mysql.inc.php
@@ -946,6 +946,34 @@ function show_status() {
946 946 return get_key_vals("SHOW STATUS");
947 947 }
948 948
  949 + /** Convert field in select and edit
  950 + * @param array one element from fields()
  951 + * @return string
  952 + */
  953 + function convert_field($field) {
  954 + if (ereg("binary", $field["type"])) {
  955 + return "HEX(" . idf_escape($field["field"]) . ")";
  956 + }
  957 + if (ereg("geometry|point|linestring|polygon", $field["type"])) {
  958 + return "AsWKT(" . idf_escape($field["field"]) . ")";
  959 + }
  960 + }
  961 +
  962 + /** Convert value in edit after applying functions back
  963 + * @param array one element from fields()
  964 + * @param string
  965 + * @return string
  966 + */
  967 + function unconvert_field($field, $return) {
  968 + if (ereg("binary", $field["type"])) {
  969 + $return = "unhex($return)";
  970 + }
  971 + if (ereg("geometry|point|linestring|polygon", $field["type"])) {
  972 + $return = "GeomFromText($return)";
  973 + }
  974 + return $return;
  975 + }
  976 +
949 977 /** Check whether a feature is supported
950 978 * @param string "comment", "copy", "drop_col", "dump", "event", "kill", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "trigger", "type", "variables", "view"
951 979 * @return bool
@@ -962,8 +990,9 @@ function support($feature) {
962 990 lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20, "decimal" => 66, "float" => 12, "double" => 21),
963 991 lang('Date and time') => array("date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4),
964 992 lang('Strings') => array("char" => 255, "varchar" => 65535, "tinytext" => 255, "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295),
965   - lang('Binary') => array("bit" => 20, "binary" => 255, "varbinary" => 65535, "tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295),
966 993 lang('Lists') => array("enum" => 65535, "set" => 64),
  994 + lang('Binary') => array("bit" => 20, "binary" => 255, "varbinary" => 65535, "tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295),
  995 + lang('Geometry') => array("geometry" => 0, "point" => 0, "linestring" => 0, "polygon" => 0, "multipoint" => 0, "multilinestring" => 0, "multipolygon" => 0, "geometrycollection" => 0),
967 996 ) as $key => $val) {
968 997 $types += $val;
969 998 $structured_types[$key] = array_keys($val);
@@ -978,7 +1007,7 @@ function support($feature) {
978 1007 "binary" => "md5/sha1",
979 1008 "date|time" => "now",
980 1009 ), array(
981   - "int|float|double|decimal" => "+/-",
  1010 + "(^|[^o])int|float|double|decimal" => "+/-", // not point
982 1011 "date" => "+ interval/- interval",
983 1012 "time" => "addtime/subtime",
984 1013 "char|text" => "concat",
7 adminer/drivers/oracle.inc.php
@@ -361,6 +361,13 @@ function show_status() {
361 361 return reset($rows);
362 362 }
363 363
  364 + function convert_field($field) {
  365 + }
  366 +
  367 + function unconvert_field($field, $return) {
  368 + return $return;
  369 + }
  370 +
364 371 function support($feature) {
365 372 return ereg("view|scheme|processlist|drop_col|variables|status", $feature); //!
366 373 }
7 adminer/drivers/pgsql.inc.php
@@ -580,6 +580,13 @@ function process_list() {
580 580 function show_status() {
581 581 }
582 582
  583 + function convert_field($field) {
  584 + }
  585 +
  586 + function unconvert_field($field, $return) {
  587 + return $return;
  588 + }
  589 +
583 590 function support($feature) {
584 591 return ereg('^(comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
585 592 }
7 adminer/drivers/sqlite.inc.php
@@ -643,6 +643,13 @@ function show_status() {
643 643 return $return;
644 644 }
645 645
  646 + function convert_field($field) {
  647 + }
  648 +
  649 + function unconvert_field($field, $return) {
  650 + return $return;
  651 + }
  652 +
646 653 function support($feature) {
647 654 return ereg('^(view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
648 655 }
9 adminer/edit.inc.php
@@ -53,7 +53,14 @@
53 53 $select = array();
54 54 foreach ($fields as $name => $field) {
55 55 if (isset($field["privileges"]["select"])) {
56   - $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : ($jush == "sql" && ereg("enum|set", $field["type"]) ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
  56 + $as = convert_field($field);
  57 + if ($_POST["clone"] && $field["auto_increment"]) {
  58 + $as = "''";
  59 + }
  60 + if ($jush == "sql" && ereg("enum|set", $field["type"])) {
  61 + $as = "1*" . idf_escape($name);
  62 + }
  63 + $select[] = ($as ? "$as AS " : "") . idf_escape($name);
57 64 }
58 65 }
59 66 $row = array();
7 adminer/include/adminer.inc.php
@@ -205,7 +205,7 @@ function selectVal($val, $link, $field) {
205 205 * @return string
206 206 */
207 207 function editVal($val, $field) {
208   - return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
  208 + return $val;
209 209 }
210 210
211 211 /** Print columns box in select
@@ -546,10 +546,7 @@ function processInput($field, $value, $function = "") {
546 546 } elseif (ereg('^(md5|sha1|password|encrypt)$', $function)) {
547 547 $return = "$function($return)";
548 548 }
549   - if (ereg("binary", $field["type"])) {
550   - $return = "unhex($return)";
551   - }
552   - return $return;
  549 + return unconvert_field($field, $return);
553 550 }
554 551
555 552 /** Returns export output options
11 adminer/select.inc.php
@@ -30,7 +30,16 @@
30 30 $where = $adminer->selectSearchProcess($fields, $indexes);
31 31 $order = $adminer->selectOrderProcess($fields, $indexes);
32 32 $limit = $adminer->selectLimitProcess();
33   -$from = ($select ? implode(", ", $select) : ($oid ? "$oid, " : "") . "*") . "\nFROM " . table($TABLE);
  33 +$from = ($select ? implode(", ", $select) : "*" . ($oid ? ", $oid" : ""));
  34 +if ($jush == "sql") {
  35 + foreach ($columns as $key => $val) {
  36 + $as = convert_field($fields[$key]);
  37 + if ($as) {
  38 + $from .= ", $as AS " . idf_escape($key);
  39 + }
  40 + }
  41 +}
  42 +$from .= "\nFROM " . table($TABLE);
34 43 $group_by = ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
35 44
36 45 if ($_GET["val"] && is_ajax()) {
1  changes.txt
@@ -6,6 +6,7 @@ Use VALUES() in INSERT+UPDATE export
6 6 Style logout button as link
7 7 Store selected database to permanent login
8 8 Ctrl+click and Shift+click on button opens form to a blank window
  9 +MySQL: Support geometry data types
9 10 Switch language by POST
10 11 Compress translations
11 12 selectQueryBuild() method (customization)
7 editor/include/adminer.inc.php
@@ -188,7 +188,7 @@ function editVal($val, $field) {
188 188 if (ereg('date|timestamp', $field["type"]) && $val !== null) {
189 189 return preg_replace('~^(\\d{2}(\\d+))-(0?(\\d+))-(0?(\\d+))~', lang('$1-$3-$5'), $val);
190 190 }
191   - return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
  191 + return $val;
192 192 }
193 193
194 194 function selectColumnsPrint($select, $columns) {
@@ -483,10 +483,7 @@ function processInput($field, $value, $function = "") {
483 483 } elseif (ereg('^(md5|sha1)$', $function)) {
484 484 $return = "$function($return)";
485 485 }
486   - if (ereg("binary", $field["type"])) {
487   - $return = "unhex($return)";
488   - }
489   - return $return;
  486 + return unconvert_field($field, $return);
490 487 }
491 488
492 489 function dumpOutput() {
2  externals/jush
... ... @@ -1 +1 @@
1   -Subproject commit 1dbb89b3d1f1aa27a067b017af44f4ef498bbaab
  1 +Subproject commit d5d52b19fb783b9ffe138496d14c7fe776b11eb4

0 comments on commit d540023

Please sign in to comment.
Something went wrong with that request. Please try again.