Re: serialize datatype for MDB2
| From: | Alan Knowles | Date: | Wed, 24 May 2006 03:42:33 +0000 |
| Subject: | Re: serialize datatype for MDB2 | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-42583@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
Hi, In my own framework webbuilder2 I have extended the datatype module of MDB2 to feature a "serialize" datatype. Using this I can simply pass in an array into any parameter and then it is automatically serialized when writing and deserialized when reading. I have refrained from adding abstract datatypes like these uptil now. Recently I added a call to serialize if someone passes an array to the quote() method without specifying an explict datatype to use. So I have sort of added 1/4 of the abstract "serialize" datatype.That does sound like magic that would come back to bite you later... -> accidentally passing an array to quote, would result in some very hard to track down bugs... - where as normally you could dedice a bug from a php error or seeing 'Array' in the database... DataObjects' Cast object does something similar, and is based on the concept that you always get raw data from the database, It should _Never_ modify it, or I hope it doesnt ;) but are allowed to send Special Objects which can behave differently when inserting/updating. Regards Alan
You can see the modified Common.php of the datatype module here: http://svn.oss.backendmedia.com/library/MDB2/Driver/Datatype/Common.phps So for the most part its just using the code for the "text" datatype with a call to serialize/unserialize as needed. Here is some sample code using "serialize" to read data from the database: http://svn.oss.backendmedia.com/library/StageLoader/SQL.phps And here is some code that uses "serialize" for data writes: http://svn.oss.backendmedia.com/modules/user_preferences/user_preferences.phps It works and its useful. The question is just if I am polluting MDB2 with a very high level feature and thereby opening the flood gates too all sorts of high level stuff. So lets have a brief discussion if there is interest and then a quick poll. regards, Lukas