From d60a7bc20fc0fc441e69b4416b021ab68e05fe24 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Tue, 25 Aug 2009 18:52:36 +0000 Subject: [PATCH] Buggy ADOdb was returning PKs in the list of indexes. Look for it in information schema and extract from results. --- lib/dml/mssql_adodb_moodle_database.php | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index f85da625f0..fc36344871 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -501,4 +501,32 @@ class mssql_adodb_moodle_database extends adodb_moodle_database { return $this->columns[$table]; } + + public function get_indexes($table) { + $indexes = parent::get_indexes($table); // AdoDB fails here, returning PK index while it shouldn't + + // Going to look for the primary key to delete it from the list of indexes + $tablename = strtoupper($this->prefix.$table); + + $sql = "SELECT c.column_name + FROM INFORMATION_SCHEMA.key_column_usage c + JOIN INFORMATION_SCHEMA.table_constraints t ON t.constraint_name = c.constraint_name + WHERE t.table_name = '$tablename' + AND t.constraint_type = 'PRIMARY KEY' + ORDER BY t.constraint_name, c.ordinal_position"; + + $this->query_start($sql, null, SQL_QUERY_AUX); + $rs = $this->adodb->Execute($sql); + $this->query_end($rs); + + $columns = $this->adodb_recordset_to_array($rs); + $rs->Close(); + /// Mimic one index array structure for easier search + $columns = array_keys($columns); + $primary_key = array('unique' => 1, 'columns' => $columns); + if ($found = array_search($primary_key, $indexes)) { + unset($indexes[$found]); + } + return $indexes; + } } -- 2.39.5