]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Support geometry data types
authorJakub Vrana <jakub@vrana.cz>
Sun, 9 Sep 2012 05:56:34 +0000 (22:56 -0700)
committerJakub Vrana <jakub@vrana.cz>
Sun, 9 Sep 2012 06:43:22 +0000 (23:43 -0700)
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/edit.inc.php
adminer/include/adminer.inc.php
adminer/select.inc.php
changes.txt
editor/include/adminer.inc.php
externals/jush

index 9f9c481e4b1e36cb8c2f2d5d3f00c0005e1a1f46..6d08375265d8b28ca1be4e43601d39bdd53c0b1f 100644 (file)
@@ -591,6 +591,13 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
                return array();
        }
 
+       function convert_field($field) {
+       }
+       
+       function unconvert_field($field, $return) {
+               return $return;
+       }
+       
        function support($feature) {
                return ereg('^(scheme|trigger|view|drop_col)$', $feature); //! routine|
        }
index 698c7959fecf1672b41578c57d470fe455028408..3fe56f8c060ae4652bffd96eb12b90e2b10ee213 100644 (file)
@@ -946,6 +946,34 @@ if (!defined("DRIVER")) {
                return get_key_vals("SHOW STATUS");
        }
        
+       /** Convert field in select and edit
+       * @param array one element from fields()
+       * @return string
+       */
+       function convert_field($field) {
+               if (ereg("binary", $field["type"])) {
+                       return "HEX(" . idf_escape($field["field"]) . ")";
+               }
+               if (ereg("geometry|point|linestring|polygon", $field["type"])) {
+                       return "AsWKT(" . idf_escape($field["field"]) . ")";
+               }
+       }
+       
+       /** Convert value in edit after applying functions back
+       * @param array one element from fields()
+       * @param string
+       * @return string
+       */
+       function unconvert_field($field, $return) {
+               if (ereg("binary", $field["type"])) {
+                       $return = "unhex($return)";
+               }
+               if (ereg("geometry|point|linestring|polygon", $field["type"])) {
+                       $return = "GeomFromText($return)";
+               }
+               return $return;
+       }
+       
        /** Check whether a feature is supported
        * @param string "comment", "copy", "drop_col", "dump", "event", "kill", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "trigger", "type", "variables", "view"
        * @return bool
@@ -962,8 +990,9 @@ if (!defined("DRIVER")) {
                lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20, "decimal" => 66, "float" => 12, "double" => 21),
                lang('Date and time') => array("date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4),
                lang('Strings') => array("char" => 255, "varchar" => 65535, "tinytext" => 255, "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295),
-               lang('Binary') => array("bit" => 20, "binary" => 255, "varbinary" => 65535, "tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295),
                lang('Lists') => array("enum" => 65535, "set" => 64),
+               lang('Binary') => array("bit" => 20, "binary" => 255, "varbinary" => 65535, "tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295),
+               lang('Geometry') => array("geometry" => 0, "point" => 0, "linestring" => 0, "polygon" => 0, "multipoint" => 0, "multilinestring" => 0, "multipolygon" => 0, "geometrycollection" => 0),
        ) as $key => $val) {
                $types += $val;
                $structured_types[$key] = array_keys($val);
@@ -978,7 +1007,7 @@ if (!defined("DRIVER")) {
                        "binary" => "md5/sha1",
                        "date|time" => "now",
                ), array(
-                       "int|float|double|decimal" => "+/-",
+                       "(^|[^o])int|float|double|decimal" => "+/-", // not point
                        "date" => "+ interval/- interval",
                        "time" => "addtime/subtime",
                        "char|text" => "concat",
index 65662bfe94bb2714f13434f737ffb44d5cabbf59..c32f2b44d91cf79dcbaf270b8b4ab0588c098a7c 100644 (file)
@@ -361,6 +361,13 @@ ORDER BY PROCESS
                return reset($rows);
        }
        
+       function convert_field($field) {
+       }
+       
+       function unconvert_field($field, $return) {
+               return $return;
+       }
+       
        function support($feature) {
                return ereg("view|scheme|processlist|drop_col|variables|status", $feature); //!
        }
index 49db9a36cc75cec3fbf05972669a4d7705cc083b..56540b5358f9a6dcdc8db3b30d03f146fe3423e0 100644 (file)
@@ -580,6 +580,13 @@ AND typelem = 0"
        function show_status() {
        }
        
+       function convert_field($field) {
+       }
+       
+       function unconvert_field($field, $return) {
+               return $return;
+       }
+       
        function support($feature) {
                return ereg('^(comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
        }
index 994d220b9cdb2ba0fca5925c805d678ab306cf61..769322b4b235ccd1078d9e851c902ac2e9d1a839 100644 (file)
@@ -643,6 +643,13 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return $return;
        }
        
+       function convert_field($field) {
+       }
+       
+       function unconvert_field($field, $return) {
+               return $return;
+       }
+       
        function support($feature) {
                return ereg('^(view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
        }
index 74ef66fb4df228e947bd5a7fd237cf472d562727..98c3e97d461e6436ab8b71abdeaa0f9b4730e745 100644 (file)
@@ -53,7 +53,14 @@ if ($_POST["save"]) {
        $select = array();
        foreach ($fields as $name => $field) {
                if (isset($field["privileges"]["select"])) {
-                       $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : ($jush == "sql" && ereg("enum|set", $field["type"]) ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
+                       $as = convert_field($field);
+                       if ($_POST["clone"] && $field["auto_increment"]) {
+                               $as = "''";
+                       }
+                       if ($jush == "sql" && ereg("enum|set", $field["type"])) {
+                               $as = "1*" . idf_escape($name);
+                       }
+                       $select[] = ($as ? "$as AS " : "") . idf_escape($name);
                }
        }
        $row = array();
index ce78f857605c0ae34a2f5280bacaed723cb34348..550f75580105b948ba3925e03d19991f61bfd5bf 100644 (file)
@@ -205,7 +205,7 @@ username.form['auth[driver]'].onchange();
        * @return string
        */
        function editVal($val, $field) {
-               return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
+               return $val;
        }
        
        /** Print columns box in select
@@ -546,10 +546,7 @@ username.form['auth[driver]'].onchange();
                } elseif (ereg('^(md5|sha1|password|encrypt)$', $function)) {
                        $return = "$function($return)";
                }
-               if (ereg("binary", $field["type"])) {
-                       $return = "unhex($return)";
-               }
-               return $return;
+               return unconvert_field($field, $return);
        }
        
        /** Returns export output options
index 386ee9bed4237f771033d9d2054fb9dca300a3e5..18bda99e93d244815e11f61a6440ef89cd7d8597 100644 (file)
@@ -30,7 +30,16 @@ $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, " : "") . "*") . "\nFROM " . table($TABLE);
+$from = ($select ? implode(", ", $select) : "*" . ($oid ? ", $oid" : ""));
+if ($jush == "sql") {
+       foreach ($columns as $key => $val) {
+               $as = convert_field($fields[$key]);
+               if ($as) {
+                       $from .= ", $as AS " . idf_escape($key);
+               }
+       }
+}
+$from .= "\nFROM " . table($TABLE);
 $group_by = ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
 
 if ($_GET["val"] && is_ajax()) {
index 1e43d8de5a9c0c27c458ae59a3fb247edc35e16f..f23f5190c6a64ab63dabd758847a55be53649575 100644 (file)
@@ -6,6 +6,7 @@ Use VALUES() in INSERT+UPDATE export
 Style logout button as link
 Store selected database to permanent login
 Ctrl+click and Shift+click on button opens form to a blank window
+MySQL: Support geometry data types
 Switch language by POST
 Compress translations
 selectQueryBuild() method (customization)
index d8e1fa41f7e1e1cba8979e6cc10aa3ddf366dfb5..ea7dc697d12fdb4c53aaeb9bb3a1c5022250498d 100644 (file)
@@ -188,7 +188,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                if (ereg('date|timestamp', $field["type"]) && $val !== null) {
                        return preg_replace('~^(\\d{2}(\\d+))-(0?(\\d+))-(0?(\\d+))~', lang('$1-$3-$5'), $val);
                }
-               return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
+               return $val;
        }
        
        function selectColumnsPrint($select, $columns) {
@@ -483,10 +483,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                } elseif (ereg('^(md5|sha1)$', $function)) {
                        $return = "$function($return)";
                }
-               if (ereg("binary", $field["type"])) {
-                       $return = "unhex($return)";
-               }
-               return $return;
+               return unconvert_field($field, $return);
        }
        
        function dumpOutput() {
index 1dbb89b3d1f1aa27a067b017af44f4ef498bbaab..d5d52b19fb783b9ffe138496d14c7fe776b11eb4 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1dbb89b3d1f1aa27a067b017af44f4ef498bbaab
+Subproject commit d5d52b19fb783b9ffe138496d14c7fe776b11eb4