Ticket #769 (new Bug)

Opened 3 months ago

Last modified 3 months ago

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

Changed 3 months ago by alf

3) Pgsql_Result::list_fields doesn't work too, because pg_field_name function accepts 2 parameters.

Fix:

public function list_fields()
{
	$field_names = array();
	for ($i = 0; $i < pg_num_fields($this->result); $i++)
		$field_names[] = pg_field_name($this->result, $i);

	return $field_names;
}
Note: See TracTickets for help on using tickets.