Ticket #769 (new Bug)
Pgsql driver bugs in field_data and list_fields functions
| Reported by: | alf | Owned by: | zombor |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.2.1 |
| Component: | Libraries:Database | Version: | SVN HEAD |
| Keywords: | pgsql list_fields field_data | Cc: |
Description
1) field_data throws an error because the first parameter of pg_query should be a connection resource, not a query:
// line 307 $query = pg_query($this->link, 'SELECT * FROM '.$this->escape_table($table).' LIMIT 1');
2) list_fields doesn't work properly with fully qualified table names (e.g., myschema.mytable). Using information_schema instead of system catalogs the query should be similar to this:
SELECT column_name AS "Field",
CASE data_type
WHEN 'integer' THEN 'int'
WHEN 'character varying' THEN 'varchar' ||
CASE WHEN character_maximum_length IS NOT NULL THEN '(' ||
character_maximum_length || ')' ELSE '' END
WHEN 'boolean' THEN 'bool'
ELSE data_type
END AS "Type",
column_default AS "Default",
is_nullable AS "Null"
FROM information_schema.columns
WHERE table_schema = 'myschema' AND table_name = 'mytable'
ORDER BY ordinal_position;
That is much easier!
I've no idea which is the mysql list_fields output, thereby the columns and types returned should be modified. If someone submits the correct output (I haven't mysql installed) I can adapt the query.
Change History
Note: See
TracTickets for help on using
tickets.
