Oracle: Fix the bugs for indexes.

Signed-off-by: Takashi SHIRAI <shirai@nintendo.co.jp>
This commit is contained in:
Takashi SHIRAI 2021-02-12 11:22:29 +09:00 committed by Jakub Vrana
parent 94d18d003e
commit eebda8695b
3 changed files with 16 additions and 10 deletions

View file

@ -308,16 +308,23 @@ ORDER BY 1"
function indexes($table, $connection2 = null) { function indexes($table, $connection2 = null) {
$return = array(); $return = array();
$owner = where_owner(" AND ", "aic.table_owner"); $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 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_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 WHERE aic.table_name = " . q($table) . "$owner
ORDER BY ac.constraint_type, aic.column_position", $connection2) as $row) { ORDER BY ac.constraint_type, aic.column_position", $connection2) as $row) {
$index_name = $row["INDEX_NAME"]; $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]["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]["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; return $return;
} }
@ -384,26 +391,23 @@ ORDER BY ac.constraint_type, aic.column_position", $connection2) as $row) {
} }
function alter_indexes($table, $alter) { function alter_indexes($table, $alter) {
$create = array();
$drop = array(); $drop = array();
$queries = array(); $queries = array();
foreach ($alter as $val) { foreach ($alter as $val) {
$val[2] = preg_replace('~ DESC$~', '', $val[2]);
if ($val[0] != "INDEX") { if ($val[0] != "INDEX") {
//! descending UNIQUE indexes results in syntax error //! 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]) ? "\nDROP CONSTRAINT " . idf_escape($val[1])
: "\nADD" . ($val[1] != "" ? " CONSTRAINT " . idf_escape($val[1]) : "") . " $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "") . "(" . implode(", ", $val[2]) . ")" : "\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") { } elseif ($val[2] == "DROP") {
$drop[] = idf_escape($val[1]); $drop[] = idf_escape($val[1]);
} else { } else {
$queries[] = "CREATE INDEX " . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) . " (" . implode(", ", $val[2]) . ")"; $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) { if ($drop) {
array_unshift($queries, "DROP INDEX " . implode(", ", $drop)); array_unshift($queries, "DROP INDEX " . implode(", ", $drop));
} }

View file

@ -1,2 +1,2 @@
<?php <?php
$VERSION = "4.8.0"; $VERSION = "4.8.1-dev";

View file

@ -1,3 +1,5 @@
Adminer 4.8.1-dev:
Adminer 4.8.0 (released 2021-02-10): Adminer 4.8.0 (released 2021-02-10):
Support function default values in insert (bug #713) Support function default values in insert (bug #713)
Allow SQL pseudo-function in insert Allow SQL pseudo-function in insert