ZF-5674: Long PostgreSQL sequence names trigger error in Zend_Db_Table_Abstract
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:
/**
* 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:
/**
* 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)