Re: [DB] returning typed data when fetching rows

From: Date: Fri, 06 Aug 2004 13:05:00 +0000
Subject: Re: [DB] returning typed data when fetching rows
References: 1 2 3  Groups: php.pear.dev php.pear.dev 
Request: Send a blank email to pear-dev+get-32477@lists.php.net to get a copy of this message
Guillaume Cocatre-Zilgien wrote:
News.Php.Net wrote:
Although I plan to use them in the near future, there is at least one feature that I find missing from them: I would like to have strongly typed data when fetching rows. If a column is of type INTEGER, I expect to get PHP integers, arrays, booleans instead of strings ('4', '{"foo","bar",{"this is foobar"}}', 't'...).
MDB and MDB2 already do this.
First, I don't seem to find in either MDB or MDB2 an automated way of fetching typed data (you have to manually pass an array of types).
Well those types need to be discovered somewhere. Doing it manually is the sensible thing to do. Fetching it automatically works well on mysql and is partly implemented in sqlite and pgsql.
Second, I don't see any code that handles PgSQL arrays, i.e. that transforms a PgSQL array ('{123, 456, 789}' into a PHP array (array (123, 456, 789)), and a PHP array into a PgSQL string representation of an array (the reverse operation).
Especially in MDB2 this is trivial to add. Just modify or extend the pgsql datatype driver. For example in my internal framework I have added the ability to use serialize/unserialize. In this case I have added this to the Common.php file of the datatype driver since I wanted this to work in all drivers.
By the way, MDB_Manager_pgsql::getTableFieldDefinition() returns an error on fields that are PgSQL arrays (of type INTEGER[] for instance).
This method is not well tested. Also it might be worthwile to better integrate it with the supported datatypes from the datatype module. So unfortunately you are not missing anything .. but MDB2 seems like the best place to me to start adding stuff like that, especially since its faster and the API was designed to handle these kinds of tasks. regards, Lukas

« previous php.pear.dev (#32477) next »