Display indexes in Oracle (thanks to Marcello Verona)

This commit is contained in:
Jakub Vrana 2011-05-06 18:04:03 +02:00
parent fb9db96e4d
commit 1da3ca544a
3 changed files with 11 additions and 9 deletions

View file

@ -334,10 +334,6 @@ WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U',
}
function indexes($table, $connection2 = null) {
global $connection;
if (!is_object($connection2)) {
$connection2 = $connection;
}
$return = array();
// sp_statistics doesn't return information about primary key
foreach (get_rows("SELECT i.name, key_ordinal, is_unique, is_primary_key, c.name AS column_name

View file

@ -425,10 +425,6 @@ if (!defined("DRIVER")) {
* @return array array($key_name => array("type" => , "columns" => array(), "lengths" => array()))
*/
function indexes($table, $connection2 = null) {
global $connection;
if (!is_object($connection2)) { // use the main connection if the separate connection is unavailable
$connection2 = $connection;
}
$return = array();
foreach (get_rows("SHOW INDEX FROM " . table($table), $connection2) as $row) {
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));

View file

@ -232,7 +232,17 @@ UNION SELECT view_name, 'view' FROM user_views" . ($name != "" ? " WHERE view_na
}
function indexes($table, $connection2 = null) {
return array(); //!
$return = array();
foreach (get_rows("SELECT uic.*, uc.constraint_type
FROM user_ind_columns uic
LEFT JOIN user_constraints uc ON uic.index_name = uc.constraint_name AND uic.table_name = uc.table_name
WHERE uic.table_name = " . q($table) . "
ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
$return[$row["INDEX_NAME"]]["type"] = ($row["CONSTRAINT_TYPE"] == "P" ? "PRIMARY" : ($row["CONSTRAINT_TYPE"] == "U" ? "UNIQUE" : "INDEX"));
$return[$row["INDEX_NAME"]]["columns"][] = $row["COLUMN_NAME"];
$return[$row["INDEX_NAME"]]["lengths"][] = ($row["CHAR_LENGTH"] && $row["CHAR_LENGTH"] != $row["COLUMN_LENGTH"] ? $row["CHAR_LENGTH"] : null);
}
return $return;
}
function view($name) {