Aleksander Machniak
2016-01-16 ed1d212ae2daea5e4bd043417610177093e99f19
program/lib/Roundcube/rcube_db_pgsql.php
@@ -73,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;
        }
@@ -140,8 +139,10 @@
        // There's a known case when max_allowed_packet is queried
        // PostgreSQL doesn't have such limit, return immediately
        if ($varname == 'max_allowed_packet') {
            return $default;
            return rcube::get_instance()->config->get('db_' . $varname, $default);
        }
        $this->variables[$varname] = rcube::get_instance()->config->get('db_' . $varname);
        if (!isset($this->variables)) {
            $this->variables = array();
@@ -154,6 +155,25 @@
        }
        return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
    }
    /**
     * Returns list of tables in a database
     *
     * @return array List of all tables of the current database
     */
    public function list_tables()
    {
        // get tables if not cached
        if ($this->tables === null) {
            $q = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"
                . " WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA NOT IN ('pg_catalog', 'information_schema')"
                . " ORDER BY TABLE_NAME");
            $this->tables = $q ? $q->fetchAll(PDO::FETCH_COLUMN, 0) : array();
        }
        return $this->tables;
    }
    /**
@@ -190,4 +210,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;
    }
}