Re: [DB] returning typed data when fetching rows

From: Date: Fri, 06 Aug 2004 16:02:42 +0000
Subject: Re: [DB] returning typed data when fetching rows
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32489@lists.php.net to get a copy of this message
Lukas Smith wrote:
DB_Table and DB_DataObjects know the types cause they work on a higher abstraction level. Basically instead of having to pass the types manually inside all queries you need to do it only once. Using the MDB[2]_Manager something like that is easily possible as well. You can define your schema in xml and then parse the file. YOu may want to serialize the xml into a format that can be parsed more quickly. Now the trick is to reorganize the array to just contain the relevant types for each query. Again DB_Table and DB_DatabObjects dont run into this problem cause they build the SQL for you. In MDB[2] you would have to use tableInfo() to get the columns in question. And it should also be possible to plugin some kind of caching there.
let me clarify this a bit more ... I am not sure exactly how you are doing things ATM or how you want to handle things. I dont think you are doing yourself a favor with discovering the types at run time. I am actually not sure either if you are doing yourself a favor if you want to discover the columns involved at runtime. But atleast discovering the columns at runtime is a bit more trivial to do (in a portable way if that is even a concern *). So lets take a look at a few options: 1) you build your sql based on classes who know the structure of the tables. then you know the types and the columns so no problem. and no runtime discovery needed, but you cant handcode your SQL. 2) you have an array containing all the types and discover at runtime the columns (including the tables) involved to be able to determine the types 3) you fetch the types of the result columns at runtime For 1) I suggest hacking DB_Table/DB_DataObject unless you want to sit down and talk to Matt about his work on the MDB_DataObject project which he started a while back. For 2) and 3) I suggest taking a close look at MDB2. *) Here is an interesting thing that MDB2 will let you do. You introduce a datatype "array". For all RDBMS that dont support arrays natively you use a text field along with serialize/unserialize and on pgsql you can use the native datatype. If you also use the MDB xml schema format to define your database schema you even get a portable database schema. regards, Lukas

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