Просмотр исходного кода

[ZF-10160] Zend_Db:

- resolved quote identifiers in name sequence.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22565 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 15 лет назад
Родитель
Сommit
264eac29ac
2 измененных файлов с 26 добавлено и 2 удалено
  1. 8 2
      library/Zend/Db/Adapter/Pdo/Pgsql.php
  2. 18 0
      tests/Zend/Db/Adapter/Pdo/PgsqlTest.php

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

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

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

@@ -207,4 +207,22 @@ class Zend_Db_Adapter_Pdo_PgsqlTest extends Zend_Db_Adapter_Pdo_TestCommon
         $this->_util->dropTable('zf_pgsql_bpchar');
         $this->assertEquals('Default', $description['pg_name']['DEFAULT']);
     }
+
+    /**
+     * @group ZF-10160
+     */
+    public function testQuoteIdentifiersInSequence()
+    {
+        $this->_util->createSequence('camelCase_id_seq');
+        $this->_db->nextSequenceId('camelCase_id_seq');
+        $this->_db->nextSequenceId($this->_db->quoteIdentifier('camelCase_id_seq', true));
+        $this->_db->lastSequenceId('camelCase_id_seq');
+        $this->_db->lastSequenceId($this->_db->quoteIdentifier('camelCase_id_seq', true));
+
+        require_once 'Zend/Db/Expr.php';
+        $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->_util->dropSequence('camelCase_id_seq');
+    }
 }