Browse Source

[ZF-10257 & ZF-10160]

- fixed break bc, supports schema.table with quote identifier.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22788 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 15 years ago
parent
commit
9a27c0205c
2 changed files with 15 additions and 2 deletions
  1. 2 2
      library/Zend/Db/Adapter/Pdo/Pgsql.php
  2. 13 0
      tests/Zend/Db/Adapter/Pdo/PgsqlTest.php

+ 2 - 2
library/Zend/Db/Adapter/Pdo/Pgsql.php

@@ -281,7 +281,7 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
     public function lastSequenceId($sequenceName)
     {
         $this->_connect();
-        $sequenceName = trim((string) $sequenceName, $this->getQuoteIdentifierSymbol());
+        $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName);
         $value = $this->fetchOne("SELECT CURRVAL("
                . $this->quote($this->quoteIdentifier($sequenceName, true))
                . ")");
@@ -299,7 +299,7 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
     public function nextSequenceId($sequenceName)
     {
         $this->_connect();
-        $sequenceName = trim((string) $sequenceName, $this->getQuoteIdentifierSymbol());
+        $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName);
         $value = $this->fetchOne("SELECT NEXTVAL("
                . $this->quote($this->quoteIdentifier($sequenceName, true))
                . ")");

+ 13 - 0
tests/Zend/Db/Adapter/Pdo/PgsqlTest.php

@@ -210,10 +210,13 @@ class Zend_Db_Adapter_Pdo_PgsqlTest extends Zend_Db_Adapter_Pdo_TestCommon
 
     /**
      * @group ZF-10160
+     * @group ZF-10257
      */
     public function testQuoteIdentifiersInSequence()
     {
         $this->_util->createSequence('camelCase_id_seq');
+        $this->_util->createSequence("single'quotes");
+
         $this->_db->nextSequenceId('camelCase_id_seq');
         $this->_db->nextSequenceId($this->_db->quoteIdentifier('camelCase_id_seq', true));
         $this->_db->lastSequenceId('camelCase_id_seq');
@@ -223,6 +226,16 @@ class Zend_Db_Adapter_Pdo_PgsqlTest extends Zend_Db_Adapter_Pdo_TestCommon
         $this->_db->lastSequenceId(new Zend_Db_Expr('camelCase_id_seq'));
         $lastId = $this->_db->lastSequenceId(new Zend_Db_Expr('camelCase_id_seq'));
         $this->assertEquals(2, $lastId);
+
+        $this->_db->nextSequenceId('"public"."camelCase_id_seq"');
+        $lastId = $this->_db->lastSequenceId('"public"."camelCase_id_seq"');
+        $this->assertEquals(3, $lastId);
+
+        $this->_db->nextSequenceId("single'quotes");
+        $lastId = $this->_db->lastSequenceId("single'quotes");
+        $this->assertEquals(1, $lastId);
+
+        $this->_util->dropSequence("single'quotes");
         $this->_util->dropSequence('camelCase_id_seq');
     }
 }