Issues

ZF-31: PostgreSQL: implement describeTable() method

Description

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

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


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

it should be something like:



     /**
     * 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

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...

Changing fix version to 0.8.0.

Rephrase summary.

Fixed in revision 3129.