Skip to content

Commit

Permalink
Oracle: Fix the bugs for 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 12, 2021
1 parent 94d18d0 commit eebda86
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
22 changes: 13 additions & 9 deletions adminer/drivers/oracle.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,23 @@ function fields($table) {
function indexes($table, $connection2 = null) {
$return = array();
$owner = where_owner(" AND ", "aic.table_owner");
foreach (get_rows("SELECT aic.*, ac.constraint_type
foreach (get_rows("SELECT aic.*, ac.constraint_type, atc.data_default
FROM all_ind_columns aic
LEFT JOIN all_constraints ac ON aic.index_name = ac.constraint_name AND aic.table_name = ac.table_name AND aic.index_owner = ac.owner
LEFT JOIN all_tab_cols atc ON aic.column_name = atc.column_name AND aic.table_name = atc.table_name AND aic.index_owner = atc.owner
WHERE aic.table_name = " . q($table) . "$owner
ORDER BY ac.constraint_type, aic.column_position", $connection2) as $row) {
$index_name = $row["INDEX_NAME"];
$column_name = $row["DATA_DEFAULT"];
if ($column_name) {
$column_name = idf_unescape($column_name);
} else {
$column_name = $row["COLUMN_NAME"];
}
$return[$index_name]["type"] = ($row["CONSTRAINT_TYPE"] == "P" ? "PRIMARY" : ($row["CONSTRAINT_TYPE"] == "U" ? "UNIQUE" : "INDEX"));
$return[$index_name]["columns"][] = $row["COLUMN_NAME"];
$return[$index_name]["columns"][] = $column_name;
$return[$index_name]["lengths"][] = ($row["CHAR_LENGTH"] && $row["CHAR_LENGTH"] != $row["COLUMN_LENGTH"] ? $row["CHAR_LENGTH"] : null);
$return[$index_name]["descs"][] = ($row["DESCEND"] ? '1' : null);
$return[$index_name]["descs"][] = ($row["DESCEND"] && $row["DESCEND"] == "DESC" ? '1' : null);
}
return $return;
}
Expand Down Expand Up @@ -384,26 +391,23 @@ 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"
$val[2] = preg_replace('~ DESC$~', '', $val[2]);
$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]) . ")"
);
array_unshift($queries, "ALTER TABLE " . table($table) . $create);
} 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));
}
Expand Down
2 changes: 1 addition & 1 deletion adminer/include/version.inc.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
$VERSION = "4.8.0";
$VERSION = "4.8.1-dev";
2 changes: 2 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Adminer 4.8.1-dev:

Adminer 4.8.0 (released 2021-02-10):
Support function default values in insert (bug #713)
Allow SQL pseudo-function in insert
Expand Down

0 comments on commit eebda86

Please sign in to comment.