Re: [DB] Suggestion for field types
| From: | Hans Lellelid | Date: | Thu, 08 Jan 2004 17:25:11 +0000 |
| Subject: | Re: [DB] Suggestion for field types | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24900@lists.php.net to get a copy of this message | ||
Peter wrote:
Thanks for the suggestions Hans. I would like to solve the problem within PEAR, though. It seems simple enough - each ext could implement a translation array eg. ( 'SQLSMINT' => 'integer', ...), or alternatively a group of functions isNumber, etc (as per my original post). Sure, of course. I agree that such a mapping is pretty useful. Feel free to look at / swipe the mappings written for the Creole drivers -- the *Types classes in driver dirs: http://creole.tigris.org/source/browse/creole/creole/classes/creole/drivers [...whew...] . I know MDB2 also supports native datatypes, though I haven't seen an explicit mapping ... I must be missing something (?).
I'm not sure I understand you here. I am getting metadata back when using PEAR to mysql, pgsql, and informix databases, as a result of a call to $db->query(). This allows me to display the colomn names for say 'select name, title from guys', where that sql is composed by the user. Ok ... maybe I'm not understanding you here either. :) Certainly you can get the column names (e.g. as keys of mysql_fetch_assoc() result) when you use $db->query("SELECT name, title FROM guys") but you don't know that name is a "string" (or better yet, "VARCHAR(100)") based on the simple resultset, right? If you wanted to find out the database types of the columns in the resultset you'd have to do an additional query -- and of course this immediately gets very complicated when you have multi-table queries, SQL functions, etc.
That tablemap idea you mention sounds like a good idea. This would also avoid developers adding dummy queries to get column info Right -- yeah. Propel uses these map classes (generated for each table) to handle type conversions when adding stuff into the database. Also, knowing about related tables allows for things like emulating ON DELETE CASCADE in MySQL.Cheers, Hans