Re: Interbase DB, again =)

From: Date: Sun, 03 Mar 2002 15:34:01 +0000
Subject: Re: Interbase DB, again =)
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-4896@lists.php.net to get a copy of this message
Ludovico Magnocavallo wrote: > > Following up on last week's (or maybe a couple of weeks ago) thread on > Interbase, get_object_vars() and DB_FETCHMODE_ASSOC, I got the latest php > snapshot where get_object_vars() behaves as expected (ie by not ignoring > empty or null object vars), but still no luck. > > It looks like ibase_get_object() returns an object with only > non-empty/non-NULL vars set, which is frankly disconcerting. :-O > I will update the php feature request, and maybe make it a bug not a feature > request, in the meantime I have hacked a small (and ugly) patch to ibase.php > to work around this problem, which is annoying me a lot in a few projects > I'm working on. > > Any comments on this issue Tomas? =) > > Ludo > > ------------------------------------------------------------------------ > Name: ibase_diff.txt > ibase_diff.txt Type: Plain Text (text/plain) > Encoding: quoted-printable Sorry for my delay in the answer, this last time I'm getting terrible busy. I reviewed your patch and looks ok (althought you know I don't have access to Interbase to test it) but have some comments on it: if ($fetchmode & DB_FETCHMODE_ASSOC) { - $ar = get_object_vars(ibase_fetch_object($result)); - if ($ar && $this->options['optimize'] == 'portability') { - $ar = array_change_key_case($ar, CASE_LOWER); + $row = ibase_fetch_row($result); + if ($row) { + if ($this->_fields === null) { + $this->_fields = array(); + $this->_num_fields = @ibase_num_fields($result); + for ($i = 0; $i < $this->_num_fields; $i++) { + $field_properties = ibase_field_info($result, $i); + if ($this->options['optimize'] == 'portability') + $this->_fields[strtolower($field_properties['alias'])] = $i; + else + $this->_fields[$field_properties['alias']] = $i; + } + } + foreach ($this->_fields as $k => $v) { + $ar[$k] = $row[$v]; + } + } else { + $ar = $row; } If I'm not understanding wrong, you are setting two vars _fields and _num_fields to the DB_common object. This will work with only one result but not with multiple, ej: $res1 = $db->query($sql); $res2 = $db->query($sql); So the way to deal with them is making that vars arrays indexed by the resource id. So: $id = (int) $result; $this->_fields[$id] = XXX; $this->_num_fields[$id] = XXX; Also the test if ($this->_fields === null) should be changed to if (isset($this->_fields[$id])). Please feel free to commit the changes by your self and if you want we could mark you as the ibase maintainer to test and attend Pear DB ibase issues. It's ok for you? Regards, Tomas V.V.Cox

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