Преглед изворни кода

ZF-3972: Wrong value for "Default value" in describeTable at pgsql adapter

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18645 44c647ce-9c0f-0410-b52a-842ac1e357ba
mikaelkael пре 16 година
родитељ
комит
0c1a88e32a
2 измењених фајлова са 18 додато и 1 уклоњено
  1. 5 1
      library/Zend/Db/Adapter/Pdo/Pgsql.php
  2. 13 0
      tests/Zend/Db/Adapter/Pdo/PgsqlTest.php

+ 5 - 1
library/Zend/Db/Adapter/Pdo/Pgsql.php

@@ -194,6 +194,7 @@ 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 (isset($matches[1])) {
@@ -202,6 +203,9 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
                         $row[$length] = null; // unlimited
                     }
                 }
+                if (preg_match("/^'(.*?)'::character varying$/", $defaultValue, $matches)) {
+                    $defaultValue = $matches[1];
+                }
             }
             list($primary, $primaryPosition, $identity) = array(false, null, false);
             if ($row[$contype] == 'p') {
@@ -215,7 +219,7 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
                 'COLUMN_NAME'      => $this->foldCase($row[$colname]),
                 'COLUMN_POSITION'  => $row[$attnum],
                 'DATA_TYPE'        => $row[$type],
-                'DEFAULT'          => $row[$default_value],
+                'DEFAULT'          => $defaultValue,
                 'NULLABLE'         => (bool) ($row[$notnull] != 't'),
                 'LENGTH'           => $row[$length],
                 'SCALE'            => null, // @todo

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

@@ -182,4 +182,17 @@ class Zend_Db_Adapter_Pdo_PgsqlTest extends Zend_Db_Adapter_Pdo_TestCommon
         return 'Pdo_Pgsql';
     }
 
+    /**
+     * @group ZF-3972
+     */
+    public function testCharacterVarying()
+    {
+        $this->_util->createTable('zf_pgsql_charvary',
+                                  array('pg_id' => 'character varying(4) NOT NULL',
+                                        'pg_info' => "character varying(1) NOT NULL DEFAULT 'A'::character varying"));
+        $description = $this->_db->describeTable('zf_pgsql_charvary');
+        $this->_util->dropTable('zf_pgsql_charvary');
+        $this->assertEquals(null , $description['pg_id']['DEFAULT']);
+        $this->assertEquals('A', $description['pg_info']['DEFAULT']);
+    }
 }