Skip to content

Commit

Permalink
MySQL: Support geometry data types
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Sep 9, 2012
1 parent 31a608e commit d540023
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 15 deletions.
7 changes: 7 additions & 0 deletions adminer/drivers/mssql.inc.php
Expand Up @@ -591,6 +591,13 @@ function show_status() {
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|
}
Expand Down
33 changes: 31 additions & 2 deletions adminer/drivers/mysql.inc.php
Expand Up @@ -946,6 +946,34 @@ function show_status() {
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
Expand All @@ -962,8 +990,9 @@ function support($feature) {
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);
Expand All @@ -978,7 +1007,7 @@ function support($feature) {
"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",
Expand Down
7 changes: 7 additions & 0 deletions adminer/drivers/oracle.inc.php
Expand Up @@ -361,6 +361,13 @@ function show_status() {
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); //!
}
Expand Down
7 changes: 7 additions & 0 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -580,6 +580,13 @@ function process_list() {
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|
}
Expand Down
7 changes: 7 additions & 0 deletions adminer/drivers/sqlite.inc.php
Expand Up @@ -643,6 +643,13 @@ function show_status() {
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);
}
Expand Down
9 changes: 8 additions & 1 deletion adminer/edit.inc.php
Expand Up @@ -53,7 +53,14 @@
$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();
Expand Down
7 changes: 2 additions & 5 deletions adminer/include/adminer.inc.php
Expand Up @@ -205,7 +205,7 @@ function selectVal($val, $link, $field) {
* @return string
*/
function editVal($val, $field) {
return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
return $val;
}

/** Print columns box in select
Expand Down Expand Up @@ -546,10 +546,7 @@ function processInput($field, $value, $function = "") {
} 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
Expand Down
11 changes: 10 additions & 1 deletion adminer/select.inc.php
Expand Up @@ -30,7 +30,16 @@
$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()) {
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions editor/include/adminer.inc.php
Expand Up @@ -188,7 +188,7 @@ function editVal($val, $field) {
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) {
Expand Down Expand Up @@ -483,10 +483,7 @@ function processInput($field, $value, $function = "") {
} 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() {
Expand Down
2 changes: 1 addition & 1 deletion externals/jush
Submodule jush updated from 1dbb89 to d5d52b

0 comments on commit d540023

Please sign in to comment.