Postgres::getTableAttributes PHP Метод

getTableAttributes() публичный Метод

Retrieve the attribute definition of a table
public getTableAttributes ( $table, $field = '' ) : All
$table The name of the table
$field (optional) The name of a field to return
Результат All attributes in order
    function getTableAttributes($table, $field = '')
    {
        $c_schema = $this->_schema;
        $this->clean($c_schema);
        $this->clean($table);
        $this->clean($field);
        if ($field == '') {
            // This query is made much more complex by the addition of the 'attisserial' field.
            // The subquery to get that field checks to see if there is an internally dependent
            // sequence on the field.
            $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\ta.attname, a.attnum,\n\t\t\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) as type,\n\t\t\t\t\ta.atttypmod,\n\t\t\t\t\ta.attnotnull, a.atthasdef, pg_catalog.pg_get_expr(adef.adbin, adef.adrelid, true) as adsrc,\n\t\t\t\t\ta.attstattarget, a.attstorage, t.typstorage,\n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT 1 FROM pg_catalog.pg_depend pd, pg_catalog.pg_class pc\n\t\t\t\t\t\tWHERE pd.objid=pc.oid\n\t\t\t\t\t\tAND pd.classid=pc.tableoid\n\t\t\t\t\t\tAND pd.refclassid=pc.tableoid\n\t\t\t\t\t\tAND pd.refobjid=a.attrelid\n\t\t\t\t\t\tAND pd.refobjsubid=a.attnum\n\t\t\t\t\t\tAND pd.deptype='i'\n\t\t\t\t\t\tAND pc.relkind='S'\n\t\t\t\t\t) IS NOT NULL AS attisserial,\n\t\t\t\t\tpg_catalog.col_description(a.attrelid, a.attnum) AS comment\n\t\t\t\tFROM\n\t\t\t\t\tpg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef\n\t\t\t\t\tON a.attrelid=adef.adrelid\n\t\t\t\t\tAND a.attnum=adef.adnum\n\t\t\t\t\tLEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid\n\t\t\t\tWHERE\n\t\t\t\t\ta.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}'\n\t\t\t\t\t\tAND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE\n\t\t\t\t\t\tnspname = '{$c_schema}'))\n\t\t\t\t\tAND a.attnum > 0 AND NOT a.attisdropped\n\t\t\t\tORDER BY a.attnum";
        } else {
            $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\ta.attname, a.attnum,\n\t\t\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) as type,\n\t\t\t\t\tpg_catalog.format_type(a.atttypid, NULL) as base_type,\n\t\t\t\t\ta.atttypmod,\n\t\t\t\t\ta.attnotnull, a.atthasdef, pg_catalog.pg_get_expr(adef.adbin, adef.adrelid, true) as adsrc,\n\t\t\t\t\ta.attstattarget, a.attstorage, t.typstorage,\n\t\t\t\t\tpg_catalog.col_description(a.attrelid, a.attnum) AS comment\n\t\t\t\tFROM\n\t\t\t\t\tpg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef\n\t\t\t\t\tON a.attrelid=adef.adrelid\n\t\t\t\t\tAND a.attnum=adef.adnum\n\t\t\t\t\tLEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid\n\t\t\t\tWHERE\n\t\t\t\t\ta.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}'\n\t\t\t\t\t\tAND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE\n\t\t\t\t\t\tnspname = '{$c_schema}'))\n\t\t\t\t\tAND a.attname = '{$field}'";
        }
        return $this->selectSet($sql);
    }
Postgres