]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Support creating array columns
authorJakub Vrana <jakub@vrana.cz>
Tue, 6 Aug 2013 22:48:45 +0000 (15:48 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 8 Aug 2013 20:52:23 +0000 (13:52 -0700)
Also allow () in length and IN.

adminer/drivers/pgsql.inc.php
adminer/include/adminer.inc.php
adminer/include/editing.inc.php
changes.txt
todo.txt

index 0240b6be4f6e093f5b368133c916d49274d2265c..9f1158d38c86c96a0d68be77a1fd550e19d20346 100644 (file)
@@ -271,12 +271,11 @@ AND a.attnum > 0
 ORDER BY a.attnum"
                ) as $row) {
                        //! collation, primary
-                       $type = $row["full_type"];
-                       if (preg_match('~(.+)\\((.*)\\)$~', $row["full_type"], $match)) {
-                               list(, $type, $row["length"]) = $match;
-                       }
+                       preg_match('~([^([]+)(\((.*)\))?((\[[0-9]*])*)$~', $row["full_type"], $match);
+                       list(, $type, $length, $row["length"], $array) = $match;
+                       $row["length"] .= $array;
                        $row["type"] = ($aliases[$type] ? $aliases[$type] : $type);
-                       $row["full_type"] = $row["type"] . ($row["length"] ? "($row[length])" : "");
+                       $row["full_type"] = $row["type"] . $length . $array;
                        $row["null"] = !$row["attnotnull"];
                        $row["auto_increment"] = preg_match('~^nextval\\(~i', $row["default"]);
                        $row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1);
index 276a15d5751afe379a75937385b749ee4454dc6b..88d0998ac3e3fecae51b5c630d8af9c0a497673c 100644 (file)
@@ -403,7 +403,7 @@ username.form['auth[driver]'].onchange();
                                $cond = " $val[op]";
                                if (preg_match('~IN$~', $val["op"])) {
                                        $in = process_length($val["val"]);
-                                       $cond .= " (" . ($in != "" ? $in : "NULL") . ")";
+                                       $cond .= " " . ($in != "" ? $in : "(NULL)");
                                } elseif ($val["op"] == "SQL") {
                                        $cond = " $val[val]"; // SQL injection
                                } elseif ($val["op"] == "LIKE %%") {
index 98aa143c698d390c739c22ea7e1951a081e6561f..040766402de8814fce29b7235ad82ad6331ba8ed 100644 (file)
@@ -153,7 +153,10 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) {
 */
 function process_length($length) {
        global $enum_length;
-       return (preg_match("~^\\s*$enum_length(?:\\s*,\\s*$enum_length)*+\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length));
+       return (preg_match("~^\\s*\\(?\\s*$enum_length(?:\\s*,\\s*$enum_length)*+\\s*\\)?\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches)
+               ? "(" . implode(",", $matches[0]) . ")"
+               : preg_replace('~[^-0-9,+()[\]]~', '', preg_replace('~^[0-9]+~', '(\1)', $length))
+       );
 }
 
 /** Create SQL string from field type
@@ -164,7 +167,7 @@ function process_length($length) {
 function process_type($field, $collate = "COLLATE") {
        global $unsigned;
        return " $field[type]"
-               . ($field["length"] != "" ? "(" . process_length($field["length"]) . ")" : "")
+               . process_length($field["length"])
                . (preg_match('~(^|[^o])int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
                . (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
        ;
index 64810672b41887c79a352ec2fa5765e37f632462..69493a82797fd6f77d45e3fcc58779c04968931f 100644 (file)
@@ -15,6 +15,7 @@ Don't append newlines to uploaded files, bug since Adminer 3.7.0
 Don't display SQL edit form on Ctrl+click on the select query, introduced in Adminer 3.6.4
 Use MD5 for editing long keys only in supported drivers, bug since Adminer 3.6.4
 PostgreSQL: Fix handling of nextval() default values
+PostgreSQL: Support creating array columns
 
 Adminer 3.7.1 (released 2013-06-29):
 Increase click target for checkboxes
index 8f848d01e4917dfe1acc8a35858e862c5e11552c..9661f6a034ecef58556cf3179e52e3cc68f5bee4 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -28,7 +28,6 @@ Delimiter in export and SQL command
 Backward keys in Editor
 
 PostgreSQL:
-Array data types
 Display number of schemas in databases overview
 Users - SELECT * FROM pg_user
 ORDER BY COUNT(*)