Procházet zdrojové kódy

ZF-9079 - Fix issue with describeTable throwing php warnings with not existing table

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21876 44c647ce-9c0f-0410-b52a-842ac1e357ba
juokaz před 15 roky
rodič
revize
7cd9488643

+ 4 - 0
library/Zend/Db/Adapter/Sqlsrv.php

@@ -437,6 +437,10 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
         $sql    = "exec sp_columns @table_name = " . $this->quoteIdentifier($tableName, true);
         $stmt   = $this->query($sql);
         $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
+        
+        if (count($result) == 0) {
+            return array();
+        }
 
         $owner           = 1;
         $table_name      = 2;

+ 11 - 0
tests/Zend/Db/Adapter/SqlsrvTest.php

@@ -164,6 +164,17 @@ class Zend_Db_Adapter_SqlsrvTest extends Zend_Db_Adapter_TestCommon
         $this->assertFalse($desc['product_name']['IDENTITY'], 'Expected product_name to return false for IDENTITY');
     }
 
+    /**
+     * test that describeTable() returns empty array on not existing table
+     * @group ZF-9079
+     */
+    public function testAdapterDescribeTableNotExistingTable()
+    {
+        $desc = $this->_db->describeTable('not_existing_table');
+
+        $this->assertEquals(0, count($desc), 'Expected to have empty result');
+    }
+
     public function testAdapterDescribeTablePrimaryKeyColumn()
     {
         $desc = $this->_db->describeTable('zfproducts');