Re: Interbase DB, again =)

From: Date: Tue, 26 Feb 2002 12:01:20 +0000
Subject: Re: Interbase DB, again =)
References: 1 2 3 4 5 6 7 8 9  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-4883@lists.php.net to get a copy of this message
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. 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

--- ibase.php Tue Feb 26 12:55:06 2002 +++ ibase_new.php Tue Feb 26 12:54:37 2002 @@ -30,6 +30,8 @@ var $phptype, $dbsyntax; var $autocommit = 1; var $manip_query = array(); + var $_fields; + var $_num_fields; function DB_ibase() { @@ -164,9 +166,24 @@ return $this->raiseError(DB_ERROR_NOT_CAPABLE); } 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; } } else { $ar = ibase_fetch_row($result); @@ -197,6 +214,8 @@ function freeQuery($query) { ibase_free_query($query); + $this->_fields = null; + $this->_num_fields = null; return true; }
« previous php.pear.dev (#4883) next »