Re: DB Informix
| From: | Peter | Date: | Tue, 06 Jan 2004 21:44:44 +0000 |
| Subject: | Re: DB Informix | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10007@lists.php.net to get a copy of this message | ||
Hi James, thanks for the quick reply!
I pasted that code into DB, and it seemed to work ok at first. I get a list of columns from
tableInfo. But the call to tableInfo breaks the result!
I tried all of these:
$tinfo = $res->tableInfo($res);
$tinfo = $res->tableInfo();
$res2 = $res; $tinfo = $res2->tableInfo($res2);
$res2 = $res; $tinfo = $res2->tableInfo();
The symptom is that with the tableInfo call, the next fetchRow returns null. Without the tableInfo
call, I don't know what the columns are, but I can access the rows.
I also noticed that numCols() returns strange results after the tableInfo call (a large number).
Perhaps the informix object is being corrupted somehow?
All this is only when using an ifx: dsn.
Kind regarads,
Peter
James 'Chip' Kaufman wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tuesday 06 January 2004 12:52, Peter wrote:
> > Hi I have have been trying to test a PHP cross db browser using
> > Informix. For this I need getListOf to work.
> >
> > The Informix implementation of DB doesn't offer much metadata, but
> > here is a small patch someone may find handy.
> >
> > The Pear code in ifx.php contained the following: ($Id: ifx.php,v
> > 1.14 2003/08/28 12:20:32 cox Exp $) 387 function
> > getSpecialQuery($type)
> > 388 {
> > 389 switch ($type) {
> > 390 case 'tables':
> > 392 default:
> >
> > Changing it to this:
> > 390 case 'tables':
> > 391 return 'select tabname from systables where
> > tabid >= 100';
> >
> > makes the getListOf call work for 'tables'. Any tips to get it to
> > fetch a list of DBs as well would be welcome :)
> >
> > Peter
> >
> > PS: I was hoping to also look at making tableInfo work. This seems
> > to involve adding a taleInfo function to ifx.php, copying from say
> > pgsql.php, and changing calls such as pg_num_fields to
> > ifx_num_fields... but perhaps its more complex than that...
>
> I submitted the following update to DB::ifx.php written by Bruno Depero.
> Perhaps it is in CVS already. It was written to support the Agata
> report project. I haven't done extensive testing, but it didn't seem to
> do anything bad. If you use it, post or email feedback if you find any
> issues.
>
> /**
> * Returns information about a table or a result set
> *
> * first test by Bruno Depero bdepero@yahoo.com
> *
> * @return array An array with all the information
> */
> function tableInfo($result, $mode = null)
> {
> $count = 0;
> $id = 0;
> $res = array();
>
> // if $result is a string, then we want information about a
> // table without a resultset
>
> if (is_string($result)) {
> $id = @ifx_query($this->connection,"SELECT FIRST 1 * FROM
> $result");
> if (empty($id)) {
> return $this->ifxraiseError();
> }
> } else { // else we want information about a resultset
> $id = $result;
> if (empty($id)) {
> return $this->ifxraiseError();
> }
> }
>
> //List of SQL fieldproperties
> $properties = @ifx_fieldproperties ($id);
> if (!isset($properties)) {
> return $this->ifxraiseError();
> }
> $count = count($properties);
>
> //$mode is just for compatibility with other databases
> if (!empty($mode)) {
> $res["num_fields"]= $count;
> }
>
> for ($i = 0; $i < $count; $i++) {
> //SQLTYPE;length;precision;scale;ISNULLABLE(Y/N)
> $fname = key ($properties);
> $field1 = $properties[$fname];
> $sqltype = substr($field1, 0, strpos($field1, ';'));
> $field1 = substr($field1, strpos($field1, ';'), 250);
> $sqllen = substr($field1, 0, strpos($field1, ';'));
>
> $res[$i]['table'] = (is_string($result)) ? $result : '';
> $res[$i]['name'] = $fname;
> $res[$i]['type'] = $sqltype;
> $res[$i]['len'] = $sqllen;
> $res[$i]['flags'] = ''; //it will be completed - now it
> isn't useful for Agata Report
> if ($mode & DB_TABLEINFO_ORDER) {
> $res['order'][$res[$i]['name']] = $i;
> }
> if ($mode & DB_TABLEINFO_ORDERTABLE) {
>
> $res['ordertable'][$res[$i]['table']][$res[$i]['name']]
> = $i;
> }
> next ($properties);
> }
>
> // free the result only if we were called on a table
> if (is_resource($id)) {
> @ifx_free_result($id);
> }
>
> return $res;
> }
>
> - --
> James 'Chip' Kaufman
> jkaufman@wamnetgov.com
> 952-346-3532
> PGP key: 697D43DE
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
>
> iD8DBQE/+wZ1rlGDUWl9Q94RAnsJAJ9UU6SoLZDli4Ho7auK3EQd/ccbfQCg2YBW
> Pm/7g39iDmDLZdRzFicSfs4=
> =oK47
> -----END PGP SIGNATURE-----