Re: [DB] Suggestion for field types

From: Date: Thu, 08 Jan 2004 17:14:48 +0000
Subject: Re: [DB] Suggestion for field types
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-24899@lists.php.net to get a copy of this message
On Jan 8, 2004, at 11:06 AM, Daniel Convissor wrote:
On Thu, Jan 08, 2004 at 12:58:43PM +0200, Peter wrote:
Hi all. Is there a mechanism in pear DB to ask about the generic field type?
I'm wondering something similar. I ran into this issue while making a new test for the tableInfo() methods. Various DBMS's spit out different types for a given field. It would be nice if at least the tests could be a little more portable so we don't get needless failures even though the thing worked. I was initially planning to add a field type translation array to the test procedure. Then I thought perahps it would be a useful thing to have in the package as a whole. But, that would lead to mission creep, since MDB already deals with this issue. What do other folks think?
I think that DB_Table provides a solution (or the start of a solution) for this. The pertinent methods are the is*() methods (isValid, isSmallint, isString, isDecimal, isDate, et al). To check if a value matches a DB_TABLE_SMALLINT type, call $dbtable->isSmallint($value). Even better, if you have defined a column map in DB_Table, all inserts and updates are validated for their column type, so all smallints are checked that they are in fact integers and in the smallint range (-32768 to +32767). Similar behaviors exist for date, time, unixtime, decimals (checks both size and scope when a column is defined) and so on. Of course, DB_Table has not been accepted yet. You can see the proposal for it here ...
     http://pear.php.net/pepr/pepr-proposal-show.php?id=14
... with links to source and full documentation. -- Paul M. Jones Savant: the simple alternative to Smarty. http://phpsavant.com/

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