From d64514aab0d812a30524107a47f8f47dfbe7ce59 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 3 May 2009 17:19:40 +0000 Subject: [PATCH] MDL-14679 - PG get_indexes() fix - minor problem retrieving indexes with columns quoted --- lib/dml/pgsql_native_moodle_database.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index 6fc7a064bba..8a6895af73f 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -290,7 +290,7 @@ class pgsql_native_moodle_database extends moodle_database { continue; } $columns = explode(',', $matches[4]); - $columns = array_map('trim', $columns); + $columns = array_map(array($this, 'trim_quotes'), $columns); $indexes[$matches[2]] = array('unique'=>!empty($matches[1]), 'columns'=>$columns); } @@ -1155,4 +1155,16 @@ class pgsql_native_moodle_database extends moodle_database { pg_free_result($result); return true; } + + /** + * Helper function trimming (whitespace + quotes) any string + * needed because PG uses to enclose with double quotes some + * fields in indexes definition and others + * + * @param string $str string to apply whitespace + quotes trim + * @return string trimmed string + */ + private function trim_quotes($str) { + return trim(trim($str), "'\""); + } }