Issues

ZF-31: PostgreSQL: implement describeTable() method

Issue Type: Bug Created: 2006-06-19T22:57:14.000+0000 Last Updated: 2007-07-05T14:43:06.000+0000 Status: Resolved Fix version(s): - 0.8.0 (21/Feb/07)

Reporter: Zend Framework (zend_framework) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db

Related issues: Attachments:

Description

http://framework.zend.com/developer/ticket/15

Zend_Db_Adapter_Pdo_Pgsql:: describeTable() is currently calling an non-existing method $this->_describeTable

<pre class="highlight">
    public function describeTable($table)
    {
        $sql = "SELECT * FROM $table LIMIT 1";
        return $this->_describeTable($sql);
    }

it should be something like:

<pre class="highlight">

     /**
     * Returns the column descriptions for a table.
     *
     * @return array
     */
    public function describeTable($table)
    {

    $sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, "
             . "a.attnotnull AS isnotnull, "
             . "( SELECT 't' "
             . "FROM pg_index "
             . "WHERE c.oid = pg_index.indrelid "
             . "AND pg_index.indkey[0] = a.attnum "
             . "AND pg_index.indisprimary = 't') AS pri, "
             . "(SELECT pg_attrdef.adsrc "
             . "FROM pg_attrdef "
             . "WHERE c.oid = pg_attrdef.adrelid "
             . "AND pg_attrdef.adnum=a.attnum) AS default "
             . "FROM pg_attribute a, pg_class c, pg_type t "
             . "WHERE c.relname = '{$table}' "
             . "AND a.attnum > 0 "
             . "AND a.attrelid = c.oid "
             . "AND a.atttypid = t.oid "
             . "ORDER BY a.attnum ";

        $result = $this->fetchAll($sql);
        $descr = array();
        foreach ($result as $key => $val) {
            $descr[$val['field']] = array(
                'name'    => $val['field'],
                'type'    => $val['type'],
                'notnull' => (bool) ($val['isnotnull'] === ''),
                'default' => $val['default'],
                'primary' => (bool) ($val['pri'] == 't'),
            );
        }
        return $descr;
    } 

Comments

Posted by Zend Framework (zend_framework) on 2006-06-19T22:57:21.000+0000

Hi,

I did something similar for Pdo_Mssql. Just in case you are not aware, the type in the returned array needs to return the length in brackets if it's a varchar. At some point, I expect a length field to be added though :)

Regards,

Rob...

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:14:32.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2006-12-26T18:43:00.000+0000

Rephrase summary.

Posted by Bill Karwin (bkarwin) on 2007-02-02T23:00:13.000+0000

Fixed in revision 3129.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts