Ver código fonte

ZF-7640: Zend_Db_Adapter_Pdo_Pgsql::describeTable() returns length -1 for fields of the type character

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19751 44c647ce-9c0f-0410-b52a-842ac1e357ba
mikaelkael 16 anos atrás
pai
commit
d14a0bb89b

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

@@ -195,15 +195,15 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
         $desc = array();
         foreach ($result as $key => $row) {
             $defaultValue = $row[$default_value];
-            if ($row[$type] == 'varchar') {
-                if (preg_match('/character varying(?:\((\d+)\))?/', $row[$complete_type], $matches)) {
+            if ($row[$type] == 'varchar' || $row[$type] == 'bpchar' ) {
+                if (preg_match('/character(?: varying)?(?:\((\d+)\))?/', $row[$complete_type], $matches)) {
                     if (isset($matches[1])) {
                         $row[$length] = $matches[1];
                     } else {
                         $row[$length] = null; // unlimited
                     }
                 }
-                if (preg_match("/^'(.*?)'::character varying$/", $defaultValue, $matches)) {
+                if (preg_match("/^'(.*?)'::(?:character varying|bpchar)$/", $defaultValue, $matches)) {
                     $defaultValue = $matches[1];
                 }
             }

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

@@ -185,7 +185,7 @@ class Zend_Db_Adapter_Pdo_PgsqlTest extends Zend_Db_Adapter_Pdo_TestCommon
     /**
      * @group ZF-3972
      */
-    public function testCharacterVarying()
+    public function testAdapterCharacterVarying()
     {
         $this->_util->createTable('zf_pgsql_charvary',
                                   array('pg_id' => 'character varying(4) NOT NULL',
@@ -195,4 +195,16 @@ class Zend_Db_Adapter_Pdo_PgsqlTest extends Zend_Db_Adapter_Pdo_TestCommon
         $this->assertEquals(null , $description['pg_id']['DEFAULT']);
         $this->assertEquals('A', $description['pg_info']['DEFAULT']);
     }
+
+    /**
+     * @group ZF-7640
+     */
+    public function testAdapterBpchar()
+    {
+        $this->_util->createTable('zf_pgsql_bpchar',
+                                  array('pg_name' => "character(100) DEFAULT 'Default'::bpchar"));
+        $description = $this->_db->describeTable('zf_pgsql_bpchar');
+        $this->_util->dropTable('zf_pgsql_bpchar');
+        $this->assertEquals('Default', $description['pg_name']['DEFAULT']);
+    }
 }