Skip to content

Commit

Permalink
PostgreSQL: Fix handling of nextval() default values (thanks to @ujov…
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Jul 2, 2013
1 parent 749f51a commit 877d9ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -252,8 +252,8 @@ function fields($table) {
$row["null"] = !$row["attnotnull"];
$row["auto_increment"] = eregi("^nextval\\(", $row["default"]);
$row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1);
if (preg_match('~^(.*)::.+$~', $row["default"], $match)) {
$row["default"] = ($match[1][0] == "'" ? idf_unescape($match[1]) : $match[1]);
if (preg_match('~(.+)::[^)]+(.*)~', $row["default"], $match)) {
$row["default"] = ($match[1][0] == "'" ? idf_unescape($match[1]) : $match[1]) . $match[2];
}
$return[$row["field"]] = $row;
}
Expand Down Expand Up @@ -372,7 +372,7 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
}
$alter[] = "ALTER $column TYPE$val[1]";
if (!$val[6]) {
$alter[] = "ALTER $column " . ($val[3] ? "SET$val[3]" : "DROP DEFAULT"); //! quoting
$alter[] = "ALTER $column " . ($val[3] ? "SET$val[3]" : "DROP DEFAULT");
$alter[] = "ALTER $column " . ($val[2] == " NULL" ? "DROP NOT" : "SET") . $val[2];
}
}
Expand Down
8 changes: 7 additions & 1 deletion adminer/include/editing.inc.php
Expand Up @@ -176,11 +176,17 @@ function process_type($field, $collate = "COLLATE") {
* @return array array("field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT")
*/
function process_field($field, $type_field) {
global $jush;
$default = $field["default"];
return array(
idf_escape(trim($field["field"])),
process_type($type_field),
($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
(isset($field["default"]) ? " DEFAULT " . ((ereg("time", $field["type"]) && eregi('^CURRENT_TIMESTAMP$', $field["default"])) || ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $field["default"])) ? $field["default"] : q($field["default"])) : ""),
(isset($default) ? " DEFAULT " . (
(ereg("time", $field["type"]) && eregi('^CURRENT_TIMESTAMP$', $default))
|| ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $default))
|| ($jush == "pgsql" && ereg("^[a-z]+\(('[^']*')+\)\$", $default))
? $default : q($default)) : ""),
($field["type"] == "timestamp" && $field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
(support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
($field["auto_increment"] ? auto_increment() : null),
Expand Down
1 change: 1 addition & 0 deletions changes.txt
@@ -1,5 +1,6 @@
Adminer 3.7.2-dev:
Save and continue edit by AJAX
PostgreSQL: Fix handling of nextval() default values

Adminer 3.7.1 (released 2013-06-29):
Increase click target for checkboxes
Expand Down

0 comments on commit 877d9ba

Please sign in to comment.