<?php
/*
-V4.22 15 Apr 2004 (c) 2000-2004 John Lim. All rights reserved.
+V5.18 3 Sep 2012 (c) 2000-2012 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
- Latest version is available at http://php.weblogs.com/
+ Latest version is available at http://adodb.sourceforge.net
Informix port by Mitchell T. Young (mitch@youngfamily.org)
*/
+// security - hide paths
+if (!defined('ADODB_DIR')) die();
+
if (!defined('IFX_SCROLL')) define('IFX_SCROLL',1);
class ADODB_informix72 extends ADOConnection {
var $fmtTimeStamp = "'Y-m-d H:i:s'";
var $hasInsertID = true;
var $hasAffectedRows = true;
- var $upperCase = 'upper';
var $substr = 'substr';
- var $metaTablesSQL="select tabname from systables";
+ var $metaTablesSQL="select tabname,tabtype from systables where tabtype in ('T','V') and owner!='informix'"; //Don't get informix tables and pseudo-tables
+
+
var $metaColumnsSQL =
-"select c.colname, c.coltype, c.collength, d.default
- from syscolumns c, systables t,sysdefaults d
- where c.tabid=t.tabid and d.tabid=t.tabid and d.colno=c.colno and tabname='%s'";
+ "select c.colname, c.coltype, c.collength, d.default,c.colno
+ from syscolumns c, systables t,outer sysdefaults d
+ where c.tabid=t.tabid and d.tabid=t.tabid and d.colno=c.colno
+ and tabname='%s' order by c.colno";
+
+ var $metaPrimaryKeySQL =
+ "select part1,part2,part3,part4,part5,part6,part7,part8 from
+ systables t,sysconstraints s,sysindexes i where t.tabname='%s'
+ and s.tabid=t.tabid and s.constrtype='P'
+ and i.idxname=s.idxname";
-// var $metaColumnsSQL = "select colname, coltype, collength from syscolumns c, systables t where c.tabid=t.tabid and tabname='%s'";
var $concat_operator = '||';
var $lastQuery = false;
{
// alternatively, use older method:
//putenv("DBDATE=Y4MD-");
-
+
// force ISO date format
putenv('GL_DATE=%Y-%m-%d');
if (isset($this->version)) return $this->version;
$arr['description'] = $this->GetOne("select DBINFO('version','full') from systables where tabid = 1");
- $arr['version'] = $this->GetOne("select DBINFO('version','major')||"."||DBINFO('version','minor') from systables where tabid = 1");
+ $arr['version'] = $this->GetOne("select DBINFO('version','major') || DBINFO('version','minor') from systables where tabid = 1");
$this->version = $arr;
return $arr;
}
return true;
}
- function RowLock($tables,$where)
+ function RowLock($tables,$where,$col='1 as adodbignore')
{
if ($this->_autocommit) $this->BeginTrans();
- return $this->GetOne("select 1 as ignore from $tables where $where for update");
+ return $this->GetOne("select $col from $tables where $where for update");
}
/* Returns: the last error message from previous database operation
function ErrorNo()
{
- preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse); //!EOS
+ preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse);
if (is_array($parse) && isset($parse[1])) return (int)$parse[1];
return 0;
}
+
+ function MetaProcedures($NamePattern = false, $catalog = null, $schemaPattern = null)
+ {
+ // save old fetch mode
+ global $ADODB_FETCH_MODE;
+
+ $false = false;
+ $save = $ADODB_FETCH_MODE;
+ $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+ if ($this->fetchMode !== FALSE) {
+ $savem = $this->SetFetchMode(FALSE);
+
+ }
+ $procedures = array ();
+
+ // get index details
+
+ $likepattern = '';
+ if ($NamePattern) {
+ $likepattern = " WHERE procname LIKE '".$NamePattern."'";
+ }
+
+ $rs = $this->Execute('SELECT procname, isproc FROM sysprocedures'.$likepattern);
+
+ if (is_object($rs)) {
+ // parse index data into array
+
+ while ($row = $rs->FetchRow()) {
+ $procedures[$row[0]] = array(
+ 'type' => ($row[1] == 'f' ? 'FUNCTION' : 'PROCEDURE'),
+ 'catalog' => '',
+ 'schema' => '',
+ 'remarks' => ''
+ );
+ }
+ }
+
+ // restore fetchmode
+ if (isset($savem)) {
+ $this->SetFetchMode($savem);
+ }
+ $ADODB_FETCH_MODE = $save;
+
+ return $procedures;
+ }
- function &MetaColumns($table)
+ function MetaColumns($table, $normalize=true)
{
global $ADODB_FETCH_MODE;
+ $false = false;
if (!empty($this->metaColumnsSQL)) {
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
- if ($rs === false) return false;
+ if ($rs === false) return $false;
+ $rspkey = $this->Execute(sprintf($this->metaPrimaryKeySQL,$table)); //Added to get primary key colno items
$retarr = array();
while (!$rs->EOF) { //print_r($rs->fields);
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
+/* //!eos.
+ $rs->fields[1] is not the correct adodb type
+ $rs->fields[2] is not correct max_length, because can include not-null bit
+
$fld->type = $rs->fields[1];
- $fld->max_length = $rs->fields[2];
+ $fld->primary_key=$rspkey->fields && array_search($rs->fields[4],$rspkey->fields); //Added to set primary key flag
+ $fld->max_length = $rs->fields[2];*/
+ $pr=ifx_props($rs->fields[1],$rs->fields[2]); //!eos
+ $fld->type = $pr[0] ;//!eos
+ $fld->primary_key=$rspkey->fields && array_search($rs->fields[4],$rspkey->fields);
+ $fld->max_length = $pr[1]; //!eos
+ $fld->precision = $pr[2] ;//!eos
+ $fld->not_null = $pr[3]=="N"; //!eos
+
if (trim($rs->fields[3]) != "AAAAAA 0") {
$fld->has_default = 1;
$fld->default_value = $rs->fields[3];
}
$rs->Close();
+ $rspkey->Close(); //!eos
return $retarr;
}
- return false;
+ return $false;
}
- function &xMetaColumns($table)
+ function xMetaColumns($table)
{
return ADOConnection::MetaColumns($table,false);
}
+ function MetaForeignKeys($table, $owner=false, $upper=false) //!Eos
+ {
+ $sql = "
+ select tr.tabname,updrule,delrule,
+ i.part1 o1,i2.part1 d1,i.part2 o2,i2.part2 d2,i.part3 o3,i2.part3 d3,i.part4 o4,i2.part4 d4,
+ i.part5 o5,i2.part5 d5,i.part6 o6,i2.part6 d6,i.part7 o7,i2.part7 d7,i.part8 o8,i2.part8 d8
+ from systables t,sysconstraints s,sysindexes i,
+ sysreferences r,systables tr,sysconstraints s2,sysindexes i2
+ where t.tabname='$table'
+ and s.tabid=t.tabid and s.constrtype='R' and r.constrid=s.constrid
+ and i.idxname=s.idxname and tr.tabid=r.ptabid
+ and s2.constrid=r.primary and i2.idxname=s2.idxname";
+
+ $rs = $this->Execute($sql);
+ if (!$rs || $rs->EOF) return false;
+ $arr = $rs->GetArray();
+ $a = array();
+ foreach($arr as $v) {
+ $coldest=$this->metaColumnNames($v["tabname"]);
+ $colorig=$this->metaColumnNames($table);
+ $colnames=array();
+ for($i=1;$i<=8 && $v["o$i"] ;$i++) {
+ $colnames[]=$coldest[$v["d$i"]-1]."=".$colorig[$v["o$i"]-1];
+ }
+ if($upper)
+ $a[strtoupper($v["tabname"])] = $colnames;
+ else
+ $a[$v["tabname"]] = $colnames;
+ }
+ return $a;
+ }
+
function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
{
$type = ($blobtype == 'TEXT') ? 1 : 0;
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
- if (!function_exists('ifx_connect')) return false;
+ if (!function_exists('ifx_connect')) return null;
$dbs = $argDatabasename . "@" . $argHostname;
if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
- if (!function_exists('ifx_connect')) return false;
+ if (!function_exists('ifx_connect')) return null;
$dbs = $argDatabasename . "@" . $argHostname;
putenv("INFORMIXSERVER=".trim($argHostname));
}
*/
// returns query ID if successful, otherwise false
- function _query($sql,$inputarr)
+ function _query($sql,$inputarr=false)
{
global $ADODB_COUNTRECS;
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
fetchField() is retrieved. */
- function &FetchField($fieldOffset = -1)
+ function FetchField($fieldOffset = -1)
{
if (empty($this->_fieldprops)) {
$fp = ifx_fieldproperties($this->_queryID);
foreach($fp as $k => $v) {
$o = new ADOFieldObject;
$o->name = $k;
- $arr = explode(';', $v); //"SQLTYPE;length;precision;scale;ISNULLABLE"
+ $arr = explode(';',$v); //"SQLTYPE;length;precision;scale;ISNULLABLE"
$o->type = $arr[0];
$o->max_length = $arr[1];
$this->_fieldprops[] = $o;
$o->not_null = $arr[4]=="N";
}
}
- return $this->_fieldprops[$fieldOffset];
+ $ret = $this->_fieldprops[$fieldOffset];
+ return $ret;
}
function _initrs()
function _seek($row)
{
- return @ifx_fetch_row($this->_queryID, $row);
+ return @ifx_fetch_row($this->_queryID, (int) $row);
}
function MoveLast()
}
}
+/** !Eos
+* Auxiliar function to Parse coltype,collength. Used by Metacolumns
+* return: array ($mtype,$length,$precision,$nullable) (similar to ifx_fieldpropierties)
+*/
+function ifx_props($coltype,$collength){
+ $itype=fmod($coltype+1,256);
+ $nullable=floor(($coltype+1) /256) ?"N":"Y";
+ $mtype=substr(" CIIFFNNDN TBXCC ",$itype,1);
+ switch ($itype){
+ case 2:
+ $length=4;
+ case 6:
+ case 9:
+ case 14:
+ $length=floor($collength/256);
+ $precision=fmod($collength,256);
+ break;
+ default:
+ $precision=0;
+ $length=$collength;
+ }
+ return array($mtype,$length,$precision,$nullable);
+}
+
+
+?>
\ No newline at end of file