On Sun, 2005-02-20 at 10:44 +0100, Lukas Smith wrote:
> Timm Friebe wrote:
> 
> > while testing PDO I was astonished to see that all values (regardless of
> > their types in the database) are returned as strings (in all extensions
> > except for PgSQL). Why is that so? It _is_ quite inconsistent, isn't it?
> > Wasn't PDO supposed to _unify_ the RDBMS access apis?
> 
> I dont know the actual implementation but at the last meeting we came to 
> the conclusion that PDO will pass back proper types if the RDBMS does 
> and strings if the RDBMS doesnt. Anything more would require the users 
> from providing this metadata or PDO jumping through alot of hoops to 
> fetch this information from the RDBMS.

For pdo_mysql (and probably most others), that's one switch statement to
solve them all:) In ext/firebird, the relevant sourcecode is even
#ifdef'd out.

If PDO extensions would returns numbers (int, float) and booleans as
their corresponding PHP datatypes this would save memory. That, for
example, was the main motivation I did this in ext/sybase_ct. There, I
try a best-match policy:

For "integers":
* If the number "fits" into a long, it will be returned into a long
  (PHP datatype integer). This can be done safely for tinyint and
  shortint, for example.

* If the number does not fit, I will try to convert it into a double
  (PHP datatype float). This is the case for e.g. numeric(10) - values
  might not fit. This is the same what PHP does when adding 1 to
  LONG_MAX, for instance. If - in the procedure of doing so, strtod()
  gives an ERANGE or if the length overflows EG(precision), I will 
  return a string.

For "floats"
* If the length of the returned value exceeds EG(precision) or if
  strtod() returns an ERANGE, I will return a string; a float otherwise.

While this sound like an awful lot of code, it actually boils down to a
couple of lines of C (which will be definitely faster than if users
first fetch column metadata and then "cast" dependant on the information
they retrieve from that).

Talking about that, maybe PDO should start returning Date objects
instead of stupid string representations or sequences of numbers of
those (where users will start preg_match()ing or strtotime()ing around
if they want to do arithmetic with the returned value)...

-- 
Timm
If it ain't broken, it doesn't have enough features yet

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to