On 01/15/2016 11:00 AM, Mathieu Parent wrote:
2016-01-14 15:59 GMT+01:00 Ivan Sergio Borgonovo <ivan....@gmail.com>:
On 01/14/2016 03:48 AM, Mathieu Parent wrote:
|...]

^^^^^^^^^^^^^^^^^^^^
I think I got it...

Great!

It'll be great when it will be patched in Debian ;)

Can you propose a PR? There are at least two usages of this pattern:
https://github.com/horde/horde/blob/master/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php#L256
https://github.com/horde/horde/blob/master/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php#L299

Propose the CURRENT_SCHEMAS() pattern first. And post the PR here.

As discussed privately I'd prefer you try to get the patch upstream. I think you've more chances to get it merged since I was just "passing by and stumbled on the bug", you're a Debian powerhouse representative.

I haven't been able to trigger the index() function during normal installation/use, but I've been able to test it with a mockup.
The tables() function was tested plenty during installation.

webmail-install and horde-db-migrate works and most importantly horde can be installed with postgres again. Everything seems functional.

I'm wondering what caused the regression. I checked briefly horde repository and didn't see anything obvious... unless the implode/explode string manipulation was bugged before and was just recently triggered by a change in SHOW search_path. But generally pg people are very careful to not break things without a good reason.

kronolith now has the right schema version etc...

The patch is attached and should work with postgres versions as remote as 8.0.

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

>From 4b62510a6278b418aaf8ed8a1b7abc416e279947 Mon Sep 17 00:00:00 2001
From: Ivan Sergio Borgonovo <m...@webthatworks.it>
Date: Fri, 15 Jan 2016 18:31:36 +0100
Subject: [PATCH] More reliable way to get list of visible indexes and table
 without dealing with search_path Got rid of bugged getSchemaSearchPath()

---
 .../Db/lib/Horde/Db/Adapter/Postgresql/Schema.php  | 26 ++--------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php
index fd16cc7..a78ddab 100644
--- a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php
+++ b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php
@@ -255,12 +255,7 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema
      */
     public function tables()
     {
-        $schemas = array();
-        foreach (explode(',', $this->getSchemaSearchPath()) as $p) {
-            $schemas[] = $this->quote($p);
-        }
-
-        return $this->selectValues('SELECT tablename FROM pg_tables WHERE schemaname IN (' . implode(',', $schemas) . ')');
+			return $this->selectValues('SELECT table_name FROM information_schema.tables WHERE table_schema = ANY (CURRENT_SCHEMAS(false));');
     }
 
     /**
@@ -301,10 +296,6 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema
         $indexes = @unserialize($this->cacheRead("tables/indexes/$tableName"));
 
         if (!$indexes) {
-            $schemas = array();
-            foreach (explode(',', $this->getSchemaSearchPath()) as $p) {
-                $schemas[] = $this->quote($p);
-            }
 
             $sql = "
               SELECT distinct i.relname, d.indisunique, a.attname
@@ -314,7 +305,7 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema
                  AND d.indisprimary = 'f'
                  AND t.oid = d.indrelid
                  AND t.relname = " . $this->quote($tableName) . "
-                 AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname IN (" . implode(',', $schemas) . ") )
+                 AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY(CURRENT_SCHEMAS(false)))
                  AND a.attrelid = t.oid
                  AND (d.indkey[0] = a.attnum OR d.indkey[1] = a.attnum
                    OR d.indkey[2] = a.attnum OR d.indkey[3] = a.attnum
@@ -1008,19 +999,6 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema
     }
 
     /**
-     * Returns the active schema search path.
-     *
-     * @return string  The active schema search path.
-     */
-    public function getSchemaSearchPath()
-    {
-        if (!$this->_schemaSearchPath) {
-            $this->_schemaSearchPath = $this->selectValue('SHOW search_path');
-        }
-        return $this->_schemaSearchPath;
-    }
-
-    /**
      * Returns the current client log message level.
      *
      * @return string  The current client log message level.
-- 
2.7.0.rc3

Reply via email to