[DB] returning typed data when fetching rows
| From: | Guillaume Cocatre-Zilgien | Date: | Thu, 05 Aug 2004 00:34:57 +0000 |
| Subject: | [DB] returning typed data when fetching rows | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-32467@lists.php.net to get a copy of this message | ||
Hello,
I have been writing a custom class for using a PostgreSQL database, while looking at the DB classes to see if I could take advantage of them.
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'...).
So I have written some functions that:
1) collect information about the columns and caches them (feature available in PEAR classes)
2) convert a PHP value into an SQL string (supports PG arrays)
3) convert a value returned by the database (string) into a typed value (supports PG arrays as well)
I think this should be implemented directly in PHP's extensions (in pg_fetch_row(), for instance), but since it isn't, I was wondering if such features would be welcome in PEAR's DB classes - not just for PostgreSQL, but also the other DB's implementations).
If they are welcome, to which class(es) should they be added? DB_Table supports some type casting, but not for fetching rows, and it doesn't support arrays.
DB_pgsql returns information about columns, but uses functions like pg_field_type(), which aren't as convenient, IMHO, as they could be.
Please let me know what you think.