Skip to content

Commit

Permalink
Support altering indexes
Browse files Browse the repository at this point in the history
Signed-off-by: Takashi SHIRAI <[email protected]>
  • Loading branch information
Takashi SHIRAI authored and vrana committed Feb 9, 2021
1 parent 98458f7 commit ef53494
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions adminer/drivers/oracle.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,38 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
;
}

function alter_indexes($table, $alter) {
$create = array();
$drop = array();
$queries = array();
foreach ($alter as $val) {
$val[2] = preg_replace('~ DESC$~', '', $val[2]);
if ($val[0] != "INDEX") {
//! descending UNIQUE indexes results in syntax error
$create[] = ($val[2] == "DROP"
? "\nDROP CONSTRAINT " . idf_escape($val[1])
: "\nADD" . ($val[1] != "" ? " CONSTRAINT " . idf_escape($val[1]) : "") . " $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "") . "(" . implode(", ", $val[2]) . ")"
);
} elseif ($val[2] == "DROP") {
$drop[] = idf_escape($val[1]);
} else {
$queries[] = "CREATE INDEX " . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) . " (" . implode(", ", $val[2]) . ")";
}
}
if ($create) {
array_unshift($queries, "ALTER TABLE " . table($table) . implode(",", $create));
}
if ($drop) {
array_unshift($queries, "DROP INDEX " . implode(", ", $drop));
}
foreach ($queries as $query) {
if (!queries($query)) {
return false;
}
}
return true;
}

function foreign_keys($table) {
$return = array();
$query = "SELECT c_list.CONSTRAINT_NAME as NAME,
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PostgreSQL: Avoid exporting empty sequence last value (bug #768)
PostgreSQL: Do not show triggers from other schemas (PR #412)
PostgreSQL: Fix multi-parameter functions in default values (bug #736)
PostgreSQL PDO: Do not select NULL function for false values in edit
Oracle: Alter indexes
Oracle: Count tables
Oracle: Import from CSV
Oracle: Fix column size with string type
Expand Down

0 comments on commit ef53494

Please sign in to comment.