Support for viewing and editing of column comments in mssql driver
This commit is contained in:
parent
9b58ecf925
commit
36e9a4d6e1
|
@ -350,7 +350,7 @@ if (isset($_GET["mssql"])) {
|
||||||
|
|
||||||
function table_status($name = "") {
|
function table_status($name = "") {
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach (get_rows("SELECT name AS Name, type_desc AS Engine FROM sys.all_objects WHERE schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND type IN ('S', 'U', 'V') " . ($name != "" ? "AND name = " . q($name) : "ORDER BY name")) as $row) {
|
foreach (get_rows("SELECT ao.name AS Name, ao.type_desc AS Engine, (SELECT value FROM fn_listextendedproperty(default, 'SCHEMA', schema_name(schema_id), 'TABLE', ao.name, null, null)) AS Comment FROM sys.all_objects AS ao WHERE schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND type IN ('S', 'U', 'V') " . ($name != "" ? "AND name = " . q($name) : "ORDER BY name")) as $row) {
|
||||||
if ($name != "") {
|
if ($name != "") {
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -368,6 +368,7 @@ if (isset($_GET["mssql"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fields($table) {
|
function fields($table) {
|
||||||
|
$comments = get_key_vals("SELECT objname, cast(value as varchar) 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]
|
||||||
FROM sys.all_columns c
|
FROM sys.all_columns c
|
||||||
|
@ -389,6 +390,7 @@ WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U',
|
||||||
"collation" => $row["collation_name"],
|
"collation" => $row["collation_name"],
|
||||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
||||||
"primary" => $row["is_identity"], //! or indexes.is_primary_key
|
"primary" => $row["is_identity"], //! or indexes.is_primary_key
|
||||||
|
"comment" => $comments[$row["name"]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -456,6 +458,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();
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$column = idf_escape($field[0]);
|
$column = idf_escape($field[0]);
|
||||||
$val = $field[1];
|
$val = $field[1];
|
||||||
|
@ -463,6 +466,8 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
|
||||||
$alter["DROP"][] = " COLUMN $column";
|
$alter["DROP"][] = " COLUMN $column";
|
||||||
} else {
|
} else {
|
||||||
$val[1] = preg_replace("~( COLLATE )'(\\w+)'~", '\1\2', $val[1]);
|
$val[1] = preg_replace("~( COLLATE )'(\\w+)'~", '\1\2', $val[1]);
|
||||||
|
$comments[$field[0]] = $val[5];
|
||||||
|
unset($val[5]);
|
||||||
if ($field[0] == "") {
|
if ($field[0] == "") {
|
||||||
$alter["ADD"][] = "\n " . implode("", $val) . ($table == "" ? substr($foreign[$val[0]], 16 + strlen($val[0])) : ""); // 16 - strlen(" FOREIGN KEY ()")
|
$alter["ADD"][] = "\n " . implode("", $val) . ($table == "" ? substr($foreign[$val[0]], 16 + strlen($val[0])) : ""); // 16 - strlen(" FOREIGN KEY ()")
|
||||||
} else {
|
} else {
|
||||||
|
@ -488,6 +493,11 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach ($comments as $key => $val) {
|
||||||
|
$comment = substr($val, 9); // 9 - strlen(" COMMENT ")
|
||||||
|
queries("EXEC sp_dropextendedproperty @name = N'MS_Description', @level0type = N'Schema', @level0name = " . q(get_schema()) . ", @level1type = N'Table', @level1name = " . q($name) . ", @level2type = N'Column', @level2name = " . q($key));
|
||||||
|
queries("EXEC sp_addextendedproperty @name = N'MS_Description', @value = " . $comment . ", @level0type = N'Schema', @level0name = " . q(get_schema()) . ", @level1type = N'Table', @level1name = " . q($name) . ", @level2type = N'Column', @level2name = " . q($key));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,7 +642,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return preg_match('~^(columns|database|drop_col|indexes|descidx|scheme|sql|table|trigger|view|view_trigger)$~', $feature); //! routine|
|
return preg_match('~^(comment|columns|database|drop_col|indexes|descidx|scheme|sql|table|trigger|view|view_trigger)$~', $feature); //! routine|
|
||||||
}
|
}
|
||||||
|
|
||||||
$jush = "mssql";
|
$jush = "mssql";
|
||||||
|
|
|
@ -7,6 +7,7 @@ MySQL: Fix displaying multi-columns foreign keys (bug #675)
|
||||||
MySQL: Fix creating users and changing password in MySQL 8 (bug #663)
|
MySQL: Fix creating users and changing password in MySQL 8 (bug #663)
|
||||||
MySQL: Pass SRID to GeomFromText
|
MySQL: Pass SRID to GeomFromText
|
||||||
PostgreSQL: Fix setting column comments on new table
|
PostgreSQL: Fix setting column comments on new table
|
||||||
|
MS SQL: Support comments
|
||||||
Elasticsearch: Fix setting number of rows
|
Elasticsearch: Fix setting number of rows
|
||||||
|
|
||||||
Adminer 4.7.1 (released 2019-01-24):
|
Adminer 4.7.1 (released 2019-01-24):
|
||||||
|
|
Loading…
Reference in a new issue