mirror of
https://github.com/vrana/adminer.git
synced 2025-08-09 16:17:48 +02:00
MS SQL alter_table
This commit is contained in:
@@ -83,7 +83,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
|
|||||||
$_POST["Comment"],
|
$_POST["Comment"],
|
||||||
($_POST["Engine"] && $_POST["Engine"] != $orig_status["Engine"] ? $_POST["Engine"] : ""),
|
($_POST["Engine"] && $_POST["Engine"] != $orig_status["Engine"] ? $_POST["Engine"] : ""),
|
||||||
($_POST["Collation"] && $_POST["Collation"] != $orig_status["Collation"] ? $_POST["Collation"] : ""),
|
($_POST["Collation"] && $_POST["Collation"] != $orig_status["Collation"] ? $_POST["Collation"] : ""),
|
||||||
($_POST["Auto_increment"] != "" ? preg_replace('~[^0-9]+~', '', $_POST["Auto_increment"]) : ""),
|
($_POST["Auto_increment"] != "" ? preg_replace('~\\D+~', '', $_POST["Auto_increment"]) : ""),
|
||||||
$partitioning
|
$partitioning
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ foreach ($engines as $engine) {
|
|||||||
<p>
|
<p>
|
||||||
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>">
|
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>">
|
||||||
<?php echo ($engines ? html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) : ""); ?>
|
<?php echo ($engines ? html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) : ""); ?>
|
||||||
<?php echo ($collations ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
|
<?php echo ($collations && $jush != "mssql" ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
|
||||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||||
<table cellspacing="0" id="edit-fields" class="nowrap">
|
<table cellspacing="0" id="edit-fields" class="nowrap">
|
||||||
<?php $comments = edit_fields($row["fields"], $collations, "TABLE", $suhosin, $foreign_keys, $row["Comment"] != ""); ?>
|
<?php $comments = edit_fields($row["fields"], $collations, "TABLE", $suhosin, $foreign_keys, $row["Comment"] != ""); ?>
|
||||||
|
@@ -145,7 +145,7 @@ if (isset($_GET["mssql"])) {
|
|||||||
if ($this->_link) {
|
if ($this->_link) {
|
||||||
$result = $this->query("SELECT SERVERPROPERTY('ProductLevel'), SERVERPROPERTY('Edition')");
|
$result = $this->query("SELECT SERVERPROPERTY('ProductLevel'), SERVERPROPERTY('Edition')");
|
||||||
$row = $result->fetch_row();
|
$row = $result->fetch_row();
|
||||||
$this->server_info = $this->result("sp_server_info 2", 2)." [$row[0]] $row[1]";
|
$this->server_info = $this->result("sp_server_info 2", 2) . " [$row[0]] $row[1]";
|
||||||
} else {
|
} else {
|
||||||
$this->error = mssql_get_last_message();
|
$this->error = mssql_get_last_message();
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,42 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function auto_increment() {
|
function auto_increment() {
|
||||||
return " IDENTITY";
|
return " IDENTITY" . ($_POST["Auto_increment"] != "" ? "(" . preg_replace('~\\D+~', '', $_POST["Auto_increment"]) . ",1)" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
|
global $connection;
|
||||||
|
$alter = array();
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$column = idf_escape($field[0]);
|
||||||
|
$val = $field[1];
|
||||||
|
if (!$val) {
|
||||||
|
$alter["DROP"][] = " COLUMN $field[0]";
|
||||||
|
} else {
|
||||||
|
$val[1] = preg_replace("~( COLLATE )'(\\w+)'~", "\\1\\2", $val[1]);
|
||||||
|
if ($field[0] == "") {
|
||||||
|
$alter["ADD"][] = "\n " . implode("", $val);
|
||||||
|
} else {
|
||||||
|
unset($val[6]); //! identity can't be removed
|
||||||
|
if ($column != $val[0]) {
|
||||||
|
queries("EXEC sp_rename " . $connection->quote(table($table) . ".$column") . ", " . $connection->quote(idf_unescape($val[0])) . ", 'COLUMN'");
|
||||||
|
}
|
||||||
|
$alter["ALTER COLUMN " . implode("", $val)][] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($table == "") {
|
||||||
|
return queries("CREATE TABLE " . table($name) . " (" . implode(",", (array) $alter["ADD"]) . "\n)");
|
||||||
|
}
|
||||||
|
if ($table != $name) {
|
||||||
|
queries("EXEC sp_rename " . $connection->quote(table($table)) . ", " . $connection->quote($name));
|
||||||
|
}
|
||||||
|
foreach ($alter as $key => $val) {
|
||||||
|
if (!queries("ALTER TABLE " . idf_escape($name) . " $key" . implode(",", $val))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function begin() {
|
function begin() {
|
||||||
|
@@ -144,7 +144,7 @@ function process_type($field, $collate = "COLLATE") {
|
|||||||
/** Create SQL string from field
|
/** Create SQL string from field
|
||||||
* @param array basic field information
|
* @param array basic field information
|
||||||
* @param array information about field type
|
* @param array information about field type
|
||||||
* @return array array("field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT")
|
* @return array array("field", " type", " NULL", " DEFAULT", " ON UPDATE", " COMMENT", " AUTO_INCREMENT")
|
||||||
*/
|
*/
|
||||||
function process_field($field, $type_field) {
|
function process_field($field, $type_field) {
|
||||||
global $connection;
|
global $connection;
|
||||||
|
Reference in New Issue
Block a user