Re: DB Informix
| From: | James 'Chip' Kaufman | Date: | Tue, 06 Jan 2004 19:03:17 +0000 |
| Subject: | Re: DB Informix | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10002@lists.php.net to get a copy of this message | ||
-----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-----