mirror of
https://github.com/vrana/adminer.git
synced 2025-08-06 14:46:36 +02:00
MS SQL: Allow changing default values
This commit is contained in:
@@ -385,7 +385,7 @@ WHERE schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND type IN ('S', 'U', 'V')
|
|||||||
function fields($table) {
|
function fields($table) {
|
||||||
$comments = get_key_vals("SELECT objname, cast(value as varchar(max)) FROM fn_listextendedproperty('MS_DESCRIPTION', 'schema', " . q(get_schema()) . ", 'table', " . q($table) . ", 'column', NULL)");
|
$comments = get_key_vals("SELECT objname, cast(value as varchar(max)) FROM fn_listextendedproperty('MS_DESCRIPTION', 'schema', " . q(get_schema()) . ", 'table', " . q($table) . ", 'column', NULL)");
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach (get_rows("SELECT c.max_length, c.precision, c.scale, c.name, c.is_nullable, c.is_identity, c.collation_name, t.name type, CAST(d.definition as text) [default]
|
foreach (get_rows("SELECT c.max_length, c.precision, c.scale, c.name, c.is_nullable, c.is_identity, c.collation_name, t.name type, CAST(d.definition as text) [default], d.name default_constraint
|
||||||
FROM sys.all_columns c
|
FROM sys.all_columns c
|
||||||
JOIN sys.all_objects o ON c.object_id = o.object_id
|
JOIN sys.all_objects o ON c.object_id = o.object_id
|
||||||
JOIN sys.types t ON c.user_type_id = t.user_type_id
|
JOIN sys.types t ON c.user_type_id = t.user_type_id
|
||||||
@@ -403,6 +403,7 @@ WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U',
|
|||||||
"type" => $type,
|
"type" => $type,
|
||||||
"length" => $length,
|
"length" => $length,
|
||||||
"default" => (preg_match("~^\('(.*)'\)$~", $row["default"], $match) ? str_replace("''", "'", $match[1]) : $row["default"]),
|
"default" => (preg_match("~^\('(.*)'\)$~", $row["default"], $match) ? str_replace("''", "'", $match[1]) : $row["default"]),
|
||||||
|
"default_constraint" => $row["default_constraint"],
|
||||||
"null" => $row["is_nullable"],
|
"null" => $row["is_nullable"],
|
||||||
"auto_increment" => $row["is_identity"],
|
"auto_increment" => $row["is_identity"],
|
||||||
"collation" => $row["collation_name"],
|
"collation" => $row["collation_name"],
|
||||||
@@ -477,6 +478,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
|
|||||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
$alter = array();
|
$alter = array();
|
||||||
$comments = array();
|
$comments = array();
|
||||||
|
$orig_fields = fields($table);
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$column = idf_escape($field[0]);
|
$column = idf_escape($field[0]);
|
||||||
$val = $field[1];
|
$val = $field[1];
|
||||||
@@ -496,8 +498,14 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
|
|||||||
queries("EXEC sp_rename " . q(table($table) . ".$column") . ", " . q(idf_unescape($val[0])) . ", 'COLUMN'");
|
queries("EXEC sp_rename " . q(table($table) . ".$column") . ", " . q(idf_unescape($val[0])) . ", 'COLUMN'");
|
||||||
}
|
}
|
||||||
$alter["ALTER COLUMN " . implode("", $val)][] = "";
|
$alter["ALTER COLUMN " . implode("", $val)][] = "";
|
||||||
if ($default) {
|
$orig_field = $orig_fields[$field[0]];
|
||||||
$alter["ADD"][] = "\n $default FOR $column";
|
if (default_value($orig_field) != $default) {
|
||||||
|
if ($orig_field["default"] !== null) {
|
||||||
|
$alter["DROP"][] = " " . idf_escape($orig_field["default_constraint"]);
|
||||||
|
}
|
||||||
|
if ($default) {
|
||||||
|
$alter["ADD"][] = "\n $default FOR $column";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ Adminer 4.16.1-dev:
|
|||||||
Hide index column options by default
|
Hide index column options by default
|
||||||
SQLite: Show all supported pragmas in Variables
|
SQLite: Show all supported pragmas in Variables
|
||||||
MS SQL: Allow altering table in non-default schema (bug #405)
|
MS SQL: Allow altering table in non-default schema (bug #405)
|
||||||
MS SQL: Display default values (bug #732)
|
MS SQL: Fix default values (bug #732, bug #733)
|
||||||
MS SQL: Fix length of nvarchar columns
|
MS SQL: Fix length of nvarchar columns
|
||||||
Editor: PDO: Select value of foreign key in edit (bug #847)
|
Editor: PDO: Select value of foreign key in edit (bug #847)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user