php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41146 pg_meta_data does not return fields description
Submitted: 2007-04-20 08:27 UTC Modified: 2014-02-16 22:04 UTC
Votes:6
Avg. Score:3.3 ± 1.4
Reproduced:4 of 5 (80.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: shade at nekto dot com Assigned: yohgaki (profile)
Status: Closed Package: PostgreSQL related
PHP Version: 5.2.1 OS: *
Private report: No CVE-ID: None
 [2007-04-20 08:27 UTC] shade at nekto dot com
Description:
------------
I found that pg_meta_data do not returns fields descriptions in result. I explore sources and found that table's meta fteched by query, citated below. I do not have free FreeBSD host for programming experiments, but i upgrade a query little bit, adding ability to fetch description from fields.

Can you use my query to add to pg_meta_data() ability to return field descriptions?

Reproduce code:
---------------
Original code:
        smart_str_appends(&querystr,
                        "SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotNULL, a.atthasdef, a.attndims "
                        "FROM pg_class as c, pg_attribute a, pg_type t "
                        "WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '");

        tmp_name = php_addslashes((char *)table_name, strlen(table_name), &new_len, 0 TSRMLS_CC);
        smart_str_appendl(&querystr, tmp_name, new_len);
        efree(tmp_name);

        smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;");
        smart_str_0(&querystr);



Changed code, that i proposes:
        smart_str_appends(&querystr,
                        "SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotNULL, a.atthasdef, a.attndims, d.description "
                        "FROM pg_class as c JOIN pg_attribute a on (a.attrelid = c.oid) JOIN pg_type t on (a.atttypid = t.oid) "
                        "LEFT JOIN pg_description d on (d.objoid=a.attrelid and d.objsubid=a.attnum and c.oid=d.objoid) "
                        "WHERE a.attnum > 0  AND c.relname = '");


        tmp_name = php_addslashes((char *)table_name, strlen(table_name), &new_len, 0 TSRMLS_CC);
        smart_str_appendl(&querystr, tmp_name, new_len);
        efree(tmp_name);

        smart_str_appends(&querystr, "' ORDER BY a.attnum;");
        smart_str_0(&querystr);


Expected result:
----------------
Information about table, including fields description (aka comments).

Actual result:
--------------
No any descriptions :(

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 14:19 UTC] jani@php.net
-Package: Feature/Change Request +Package: PostgreSQL related
 [2010-12-20 14:19 UTC] jani@php.net
-Operating System: Windows, FreeBSD +Operating System: *
 [2011-11-08 06:05 UTC] yohgaki at ohgaki dot net
The reason that the function fails is PostgreSQL's schema is changed when minor 
version is updated.

I'll look into so that it can perform proper query for current connection.
 [2014-02-16 22:04 UTC] yohgaki@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC