[Fwd: Re: [PEAR-DEV] serialize datatype for MDB2]
| From: | Lukas Smith | Date: | Mon, 29 May 2006 11:42:21 +0000 |
| Subject: | [Fwd: Re: [PEAR-DEV] serialize datatype for MDB2] | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-42664@lists.php.net to get a copy of this message | ||
that should have gone to the list ..
-------- Original Message --------
Subject: Re: [PEAR-DEV] serialize datatype for MDB2
Date: Mon, 29 May 2006 13:42:11 +0200
From: Patrick Müller <elias0@gmx.net>
To: Lukas Smith <lsmith@php.net>
References: <64.D3.19568.0C573744@pb1.pair.com> <4473D629.2070708@akbkhome.com> <44741228.2060804@php.net> <447ACC83.3010206@php.net>
Lukas Smith wrote:
Lukas Smith wrote:+1 for the feature itself, but a big -1 if it is not very strict implemented. in most cases arrays inserted accidentally, in that case i'd prefer an fatal or warning. $array = array('foo'); $mdb2->quote($array); // fatal error $mdb2->quote($array, 'text') // fatal error $mdb2->quote($array, 'serialize') // ok i'm a bit unsure about the deserialization. there only two ways of deserialization which makes sense are text and serialize. in a defensive manner you can try to detect an serialized array/object and throw an warning if something like int is requested. $result = $mdb2->query('SELECT someint, somearray FROM foo', array('integer', 'integer')); $row = $result->fetchRow() //warning error eliasAlan Knowles wrote:So any more opinions? Right now I have a +1, -1 and a -0,5Lukas Smith wrote:Well it would not happen if you explicitly pass a datatype. Not passing in a datatype. And actually my question was more concerned about introducing a new explicit datatype serialize. $array = array('foo'); $mdb2->quote($array); // returns a serialized string because no datatype was giving $mdb2->quote($array, 'text') // would probably give a notice due to an implict array to string cast done by php $mdb2->quote($array, 'serialize') // returns a serialized string as requested $result = $mdb2->query('SELECT someint, somearray FROM foo', array('integer', 'serialize')); $row = $result->fetchRow() // would return an array with an integer and whatever was serialized into the somearray columnHi, 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...