Issues

ZF-5674: Long PostgreSQL sequence names trigger error in Zend_Db_Table_Abstract

Issue Type: Bug Created: 2009-02-02T19:48:16.000+0000 Last Updated: 2009-11-20T13:47:02.000+0000 Status: Resolved Fix version(s): Reporter: Brad Griffith (griffbrad) Assignee: Mickael Perraud (mikaelkael) Tags: - Zend_Db_Table

Related issues: Attachments:

Description

In PostgreSQL, when the SERIAL datatype is used it creates a sequence on that column that provides an equivalent to the AUTO_INCREMENT attribute on columns in MySQL. That sequence gets an auto-generated name which follows this format:

<

table>__seq

However, the entire sequence name can only be up to 60 characters long. Because of this, the existing code to accommodate this aspect of PostgreSQL is incorrect. This block of code:

<pre class="highlight">
        /**
         * Special case for PostgreSQL: a SERIAL key implicitly uses a sequence
         * object whose name is "

__seq".
         */
        if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
            $this->_sequence = "{$this->_name}_{$pkIdentity}_seq";
            if ($this->_schema) {
                $this->_sequence = $this->_schema . '.' . $this->_sequence;
            }
        }

Should actually be:

<pre class="highlight">
        /**
         * Special case for PostgreSQL: a SERIAL key implicitly uses a sequence
         * object whose name is "

__seq".
         */
        if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
            $this->_sequence = "{$this->_name}_{$pkIdentity}_seq";
            
            if (59 < strlen($this->_sequence)) {
                $table     = substr($this->_name, 0, 29) . '_';
                $remainder = 59 - strlen($table);
                $field     = substr($pkIdentity, 0, $remainder);
                
                $this->_sequence = $table . $field . '_seq';
            }
            
            if ($this->_schema) {
                $this->_sequence = $this->_schema . '.' . $this->_sequence;
            }
        }

In order for the Zend-constructed name to match the name made by PostgreSQL when the table is created, the additional if block that check the length of the sequence name is needed.

Comments

Posted by Mickael Perraud (mikaelkael) on 2009-11-20T13:47:02.000+0000

Test added with r19141 But cannot reproduce. Please reopen if necessary with more informations about environment (OS, PHP, Pgsql version)

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts