Zend Framework

PostgreSQL: Incorrect sequence name quoting

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.8.2
  • Component/s: Zend_Db
  • Labels:
    None

Description

As per http://www.postgresql.org/docs/8.2/interactive/functions-sequence.html quoting a mixed-case sequence name requires putting it also in " ", otherwise the name will be converted to lower-case. Zend_Db_Adapter_Pdo_Pgsql never adds the additional doublequotes mentioned, only the typical singlequtoes used for string constants. Column name quoting in SELECT statements made by the PostgreSQL adapter, however, seems to know about this requirement. As far as I can tell, the problem lies in the following functions:

public function lastSequenceId($sequenceName)
    {
        $this->_connect();
        $value = $this->fetchOne("SELECT CURRVAL(".$this->quote($sequenceName).")");
        return $value;
    }

    public function nextSequenceId($sequenceName)
    {
        $this->_connect();
        $value = $this->fetchOne("SELECT NEXTVAL(".$this->quote($sequenceName).")");
        return $value;
    }

I would have prepared a patch if I knew how (in terms of design and abstracting this additional quoting process) this should be done.

Activity

Hide
Darby Felton added a comment -

Assigning to Bill Karwin to initiate issue review.

Show
Darby Felton added a comment - Assigning to Bill Karwin to initiate issue review.
Hide
Krasimir Yosifov added a comment - - edited

I think that problem is here:
Zend_Db_Table_Abstract.php
from line 665

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;
            }
        }

I suggest this code

if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
            $this->_sequence = $this->_db->quoteIdentifier("{$this->_name}_{$pkIdentity}_seq");
            if ($this->_schema) {
                $this->_sequence = $this->_db->quoteIdentifier($this->_schema) . '.' . $this->_sequence;
            }
        }
Show
Krasimir Yosifov added a comment - - edited I think that problem is here: Zend_Db_Table_Abstract.php from line 665
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;
            }
        }
I suggest this code
if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
            $this->_sequence = $this->_db->quoteIdentifier("{$this->_name}_{$pkIdentity}_seq");
            if ($this->_schema) {
                $this->_sequence = $this->_db->quoteIdentifier($this->_schema) . '.' . $this->_sequence;
            }
        }
Hide
Krasimir Yosifov added a comment -

Sorry for reposting but I made a mistake in my first comment. So the fixed one is here:

I think that the problem is here:
Zend_Db_Table_Abstract.php
line 665

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;
    }
}

I suggest this code

if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
    $this->sequence = $this->_db->quoteIdentifier("{$this->_name}{$pkIdentity}_seq");
    if ($this->_schema) {
        $this->_sequence = $this->_db->quoteIdentifier($this->_schema) . '.' . $this->_sequence;
    }
}
Show
Krasimir Yosifov added a comment - Sorry for reposting but I made a mistake in my first comment. So the fixed one is here: I think that the problem is here: Zend_Db_Table_Abstract.php line 665
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;
    }
}
I suggest this code
if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
    $this->sequence = $this->_db->quoteIdentifier("{$this->_name}{$pkIdentity}_seq");
    if ($this->_schema) {
        $this->_sequence = $this->_db->quoteIdentifier($this->_schema) . '.' . $this->_sequence;
    }
}
Hide
Wil Sinclair added a comment -

This issue should have been fixed for the 1.5 release.

Show
Wil Sinclair added a comment - This issue should have been fixed for the 1.5 release.
Hide
Wil Sinclair added a comment -

Please categorize/fix as needed.

Show
Wil Sinclair added a comment - Please categorize/fix as needed.
Hide
Wil Sinclair added a comment -

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Show
Wil Sinclair added a comment - This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.
Hide
Wil Sinclair added a comment -

This issue has gone unaddressed for too long. I'm re-assigning to Ralph for re-evaluation and categorization.

Show
Wil Sinclair added a comment - This issue has gone unaddressed for too long. I'm re-assigning to Ralph for re-evaluation and categorization.
Hide
Ralph Schindler added a comment -

Will evaluate within 2 weeks

Show
Ralph Schindler added a comment - Will evaluate within 2 weeks
Hide
Ralph Schindler added a comment -

Fixed in r15676

Show
Ralph Schindler added a comment - Fixed in r15676

People

Vote (6)
Watch (8)

Dates

  • Due:
    Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
4h
Original Estimate - 4 hours
Remaining:
4h
Remaining Estimate - 4 hours
Logged:
Not Specified
Time Spent - Not Specified