From ecf6c79d00a8ed722a6664f276a0f015de4d13c2 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 09 Dec 2014 04:43:25 -0500
Subject: [PATCH] Bump up version number, remove package.xml file

---
 program/lib/Roundcube/rcube_db_pgsql.php |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/program/lib/Roundcube/rcube_db_pgsql.php b/program/lib/Roundcube/rcube_db_pgsql.php
index 984dd57..a92d3cf 100644
--- a/program/lib/Roundcube/rcube_db_pgsql.php
+++ b/program/lib/Roundcube/rcube_db_pgsql.php
@@ -29,6 +29,17 @@
     public $db_provider = 'postgres';
 
     /**
+     * Driver-specific configuration of database connection
+     *
+     * @param array $dsn DSN for DB connections
+     * @param PDO   $dbh Connection handler
+     */
+    protected function conn_configure($dsn, $dbh)
+    {
+        $dbh->query("SET NAMES 'utf8'");
+    }
+
+    /**
      * Get last inserted record ID
      *
      * @param string $table Table name (to find the incremented sequence)
@@ -62,10 +73,9 @@
         // Note: we support only one sequence per table
         // Note: The sequence name must be <table_name>_seq
         $sequence = $table . '_seq';
-        $rcube    = rcube::get_instance();
 
-        // return sequence name if configured
-        if ($prefix = $rcube->config->get('db_prefix')) {
+        // modify sequence name if prefix is configured
+        if ($prefix = $this->options['table_prefix']) {
             return $prefix . $sequence;
         }
 
@@ -179,4 +189,24 @@
         return $result;
     }
 
+    /**
+     * Parse SQL file and fix table names according to table prefix
+     */
+    protected function fix_table_names($sql)
+    {
+        if (!$this->options['table_prefix']) {
+            return $sql;
+        }
+
+        $sql = parent::fix_table_names($sql);
+
+        // replace sequence names, and other postgres-specific commands
+        $sql = preg_replace_callback(
+            '/((SEQUENCE |RENAME TO |nextval\()["\']*)([^"\' \r\n]+)/',
+            array($this, 'fix_table_names_callback'),
+            $sql
+        );
+
+        return $sql;
+    }
 }

--
Gitblit v1.9.1