00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 if (!defined('ADODB_DIR')) die();
00019
00020 if (!defined('IFX_SCROLL')) define('IFX_SCROLL',1);
00021
00022 class ADODB_informix72 extends ADOConnection {
00023 var $databaseType = "informix72";
00024 var $dataProvider = "informix";
00025 var $replaceQuote = "''";
00026 var $fmtDate = "'Y-m-d'";
00027 var $fmtTimeStamp = "'Y-m-d H:i:s'";
00028 var $hasInsertID = true;
00029 var $hasAffectedRows = true;
00030 var $substr = 'substr';
00031 var $metaTablesSQL="select tabname,tabtype from systables where tabtype in ('T','V') and owner!='informix'";
00032
00033
00034 var $metaColumnsSQL =
00035 "select c.colname, c.coltype, c.collength, d.default,c.colno
00036 from syscolumns c, systables t,outer sysdefaults d
00037 where c.tabid=t.tabid and d.tabid=t.tabid and d.colno=c.colno
00038 and tabname='%s' order by c.colno";
00039
00040 var $metaPrimaryKeySQL =
00041 "select part1,part2,part3,part4,part5,part6,part7,part8 from
00042 systables t,sysconstraints s,sysindexes i where t.tabname='%s'
00043 and s.tabid=t.tabid and s.constrtype='P'
00044 and i.idxname=s.idxname";
00045
00046 var $concat_operator = '||';
00047
00048 var $lastQuery = false;
00049 var $has_insertid = true;
00050
00051 var $_autocommit = true;
00052 var $_bindInputArray = true;
00053 var $sysDate = 'TODAY';
00054 var $sysTimeStamp = 'CURRENT';
00055 var $cursorType = IFX_SCROLL;
00056
00057 function ADODB_informix72()
00058 {
00059
00060
00061
00062
00063 putenv('GL_DATE=%Y-%m-%d');
00064
00065 if (function_exists('ifx_byteasvarchar')) {
00066 ifx_byteasvarchar(1);
00067 ifx_textasvarchar(1);
00068 ifx_blobinfile_mode(0);
00069 }
00070 }
00071
00072 function ServerInfo()
00073 {
00074 if (isset($this->version)) return $this->version;
00075
00076 $arr['description'] = $this->GetOne("select DBINFO('version','full') from systables where tabid = 1");
00077 $arr['version'] = $this->GetOne("select DBINFO('version','major') || DBINFO('version','minor') from systables where tabid = 1");
00078 $this->version = $arr;
00079 return $arr;
00080 }
00081
00082
00083
00084 function _insertid()
00085 {
00086 $sqlca =ifx_getsqlca($this->lastQuery);
00087 return @$sqlca["sqlerrd1"];
00088 }
00089
00090 function _affectedrows()
00091 {
00092 if ($this->lastQuery) {
00093 return @ifx_affected_rows ($this->lastQuery);
00094 }
00095 return 0;
00096 }
00097
00098 function BeginTrans()
00099 {
00100 if ($this->transOff) return true;
00101 $this->transCnt += 1;
00102 $this->Execute('BEGIN');
00103 $this->_autocommit = false;
00104 return true;
00105 }
00106
00107 function CommitTrans($ok=true)
00108 {
00109 if (!$ok) return $this->RollbackTrans();
00110 if ($this->transOff) return true;
00111 if ($this->transCnt) $this->transCnt -= 1;
00112 $this->Execute('COMMIT');
00113 $this->_autocommit = true;
00114 return true;
00115 }
00116
00117 function RollbackTrans()
00118 {
00119 if ($this->transOff) return true;
00120 if ($this->transCnt) $this->transCnt -= 1;
00121 $this->Execute('ROLLBACK');
00122 $this->_autocommit = true;
00123 return true;
00124 }
00125
00126 function RowLock($tables,$where,$flds='1 as ignore')
00127 {
00128 if ($this->_autocommit) $this->BeginTrans();
00129 return $this->GetOne("select $flds from $tables where $where for update");
00130 }
00131
00132
00133
00134
00135 function ErrorMsg()
00136 {
00137 if (!empty($this->_logsql)) return $this->_errorMsg;
00138 $this->_errorMsg = ifx_errormsg();
00139 return $this->_errorMsg;
00140 }
00141
00142 function ErrorNo()
00143 {
00144 preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse);
00145 if (is_array($parse) && isset($parse[1])) return (int)$parse[1];
00146 return 0;
00147 }
00148
00149
00150 function &MetaColumns($table)
00151 {
00152 global $ADODB_FETCH_MODE;
00153
00154 $false = false;
00155 if (!empty($this->metaColumnsSQL)) {
00156 $save = $ADODB_FETCH_MODE;
00157 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00158 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
00159 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
00160 if (isset($savem)) $this->SetFetchMode($savem);
00161 $ADODB_FETCH_MODE = $save;
00162 if ($rs === false) return $false;
00163 $rspkey = $this->Execute(sprintf($this->metaPrimaryKeySQL,$table));
00164
00165 $retarr = array();
00166 while (!$rs->EOF) {
00167 $fld = new ADOFieldObject();
00168 $fld->name = $rs->fields[0];
00169
00170
00171
00172
00173
00174
00175
00176 $pr=ifx_props($rs->fields[1],$rs->fields[2]);
00177 $fld->type = $pr[0] ;
00178 $fld->primary_key=$rspkey->fields && array_search($rs->fields[4],$rspkey->fields);
00179 $fld->max_length = $pr[1];
00180 $fld->precision = $pr[2] ;
00181 $fld->not_null = $pr[3]=="N";
00182
00183 if (trim($rs->fields[3]) != "AAAAAA 0") {
00184 $fld->has_default = 1;
00185 $fld->default_value = $rs->fields[3];
00186 } else {
00187 $fld->has_default = 0;
00188 }
00189
00190 $retarr[strtolower($fld->name)] = $fld;
00191 $rs->MoveNext();
00192 }
00193
00194 $rs->Close();
00195 $rspKey->Close();
00196 return $retarr;
00197 }
00198
00199 return $false;
00200 }
00201
00202 function &xMetaColumns($table)
00203 {
00204 return ADOConnection::MetaColumns($table,false);
00205 }
00206
00207 function MetaForeignKeys($table, $owner=false, $upper=false)
00208 {
00209 $sql = "
00210 select tr.tabname,updrule,delrule,
00211 i.part1 o1,i2.part1 d1,i.part2 o2,i2.part2 d2,i.part3 o3,i2.part3 d3,i.part4 o4,i2.part4 d4,
00212 i.part5 o5,i2.part5 d5,i.part6 o6,i2.part6 d6,i.part7 o7,i2.part7 d7,i.part8 o8,i2.part8 d8
00213 from systables t,sysconstraints s,sysindexes i,
00214 sysreferences r,systables tr,sysconstraints s2,sysindexes i2
00215 where t.tabname='$table'
00216 and s.tabid=t.tabid and s.constrtype='R' and r.constrid=s.constrid
00217 and i.idxname=s.idxname and tr.tabid=r.ptabid
00218 and s2.constrid=r.primary and i2.idxname=s2.idxname";
00219
00220 $rs = $this->Execute($sql);
00221 if (!$rs || $rs->EOF) return false;
00222 $arr =& $rs->GetArray();
00223 $a = array();
00224 foreach($arr as $v) {
00225 $coldest=$this->metaColumnNames($v["tabname"]);
00226 $colorig=$this->metaColumnNames($table);
00227 $colnames=array();
00228 for($i=1;$i<=8 && $v["o$i"] ;$i++) {
00229 $colnames[]=$coldest[$v["d$i"]-1]."=".$colorig[$v["o$i"]-1];
00230 }
00231 if($upper)
00232 $a[strtoupper($v["tabname"])] = $colnames;
00233 else
00234 $a[$v["tabname"]] = $colnames;
00235 }
00236 return $a;
00237 }
00238
00239 function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
00240 {
00241 $type = ($blobtype == 'TEXT') ? 1 : 0;
00242 $blobid = ifx_create_blob($type,0,$val);
00243 return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blobid));
00244 }
00245
00246 function BlobDecode($blobid)
00247 {
00248 return function_exists('ifx_byteasvarchar') ? $blobid : @ifx_get_blob($blobid);
00249 }
00250
00251
00252 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
00253 {
00254 if (!function_exists('ifx_connect')) return null;
00255
00256 $dbs = $argDatabasename . "@" . $argHostname;
00257 if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
00258 putenv("INFORMIXSERVER=".trim($argHostname));
00259 $this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword);
00260 if ($this->_connectionID === false) return false;
00261 #if ($argDatabasename) return $this->SelectDB($argDatabasename);
00262 return true;
00263 }
00264
00265
00266 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
00267 {
00268 if (!function_exists('ifx_connect')) return null;
00269
00270 $dbs = $argDatabasename . "@" . $argHostname;
00271 putenv("INFORMIXSERVER=".trim($argHostname));
00272 $this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword);
00273 if ($this->_connectionID === false) return false;
00274 #if ($argDatabasename) return $this->SelectDB($argDatabasename);
00275 return true;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 function _query($sql,$inputarr)
00288 {
00289 global $ADODB_COUNTRECS;
00290
00291
00292 if ($inputarr) {
00293 foreach($inputarr as $v) {
00294 if (gettype($v) == 'string') {
00295 $tab[] = ifx_create_char($v);
00296 }
00297 else {
00298 $tab[] = $v;
00299 }
00300 }
00301 }
00302
00303
00304
00305 if (!$ADODB_COUNTRECS && preg_match("/^\s*select/is", $sql)) {
00306 if ($inputarr) {
00307 $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType, $tab);
00308 }
00309 else {
00310 $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType);
00311 }
00312 }
00313 else {
00314 if ($inputarr) {
00315 $this->lastQuery = ifx_query($sql,$this->_connectionID, $tab);
00316 }
00317 else {
00318 $this->lastQuery = ifx_query($sql,$this->_connectionID);
00319 }
00320 }
00321
00322
00323
00324
00325
00326
00327 return $this->lastQuery;
00328 }
00329
00330
00331 function _close()
00332 {
00333 $this->lastQuery = false;
00334 return ifx_close($this->_connectionID);
00335 }
00336 }
00337
00338
00339
00340
00341
00342
00343 class ADORecordset_informix72 extends ADORecordSet {
00344
00345 var $databaseType = "informix72";
00346 var $canSeek = true;
00347 var $_fieldprops = false;
00348
00349 function ADORecordset_informix72($id,$mode=false)
00350 {
00351 if ($mode === false) {
00352 global $ADODB_FETCH_MODE;
00353 $mode = $ADODB_FETCH_MODE;
00354 }
00355 $this->fetchMode = $mode;
00356 return $this->ADORecordSet($id);
00357 }
00358
00359
00360
00361
00362
00363
00364
00365 function &FetchField($fieldOffset = -1)
00366 {
00367 if (empty($this->_fieldprops)) {
00368 $fp = ifx_fieldproperties($this->_queryID);
00369 foreach($fp as $k => $v) {
00370 $o = new ADOFieldObject;
00371 $o->name = $k;
00372 $arr = split(';',$v);
00373 $o->type = $arr[0];
00374 $o->max_length = $arr[1];
00375 $this->_fieldprops[] = $o;
00376 $o->not_null = $arr[4]=="N";
00377 }
00378 }
00379 $ret = $this->_fieldprops[$fieldOffset];
00380 return $ret;
00381 }
00382
00383 function _initrs()
00384 {
00385 $this->_numOfRows = -1;
00386 $this->_numOfFields = ifx_num_fields($this->_queryID);
00387 }
00388
00389 function _seek($row)
00390 {
00391 return @ifx_fetch_row($this->_queryID, (int) $row);
00392 }
00393
00394 function MoveLast()
00395 {
00396 $this->fields = @ifx_fetch_row($this->_queryID, "LAST");
00397 if ($this->fields) $this->EOF = false;
00398 $this->_currentRow = -1;
00399
00400 if ($this->fetchMode == ADODB_FETCH_NUM) {
00401 foreach($this->fields as $v) {
00402 $arr[] = $v;
00403 }
00404 $this->fields = $arr;
00405 }
00406
00407 return true;
00408 }
00409
00410 function MoveFirst()
00411 {
00412 $this->fields = @ifx_fetch_row($this->_queryID, "FIRST");
00413 if ($this->fields) $this->EOF = false;
00414 $this->_currentRow = 0;
00415
00416 if ($this->fetchMode == ADODB_FETCH_NUM) {
00417 foreach($this->fields as $v) {
00418 $arr[] = $v;
00419 }
00420 $this->fields = $arr;
00421 }
00422
00423 return true;
00424 }
00425
00426 function _fetch($ignore_fields=false)
00427 {
00428
00429 $this->fields = @ifx_fetch_row($this->_queryID);
00430
00431 if (!is_array($this->fields)) return false;
00432
00433 if ($this->fetchMode == ADODB_FETCH_NUM) {
00434 foreach($this->fields as $v) {
00435 $arr[] = $v;
00436 }
00437 $this->fields = $arr;
00438 }
00439 return true;
00440 }
00441
00442
00443
00444 function _close()
00445 {
00446 return ifx_free_result($this->_queryID);
00447 }
00448
00449 }
00454 function ifx_props($coltype,$collength){
00455 $itype=fmod($coltype+1,256);
00456 $nullable=floor(($coltype+1) /256) ?"N":"Y";
00457 $mtype=substr(" CIIFFNNDN TBXCC ",$itype,1);
00458 switch ($itype){
00459 case 2:
00460 $length=4;
00461 case 6:
00462 case 9:
00463 case 14:
00464 $length=floor($collength/256);
00465 $precision=fmod($collength,256);
00466 break;
00467 default:
00468 $precision=0;
00469 $length=$collength;
00470 }
00471 return array($mtype,$length,$precision,$nullable);
00472 }
00473
00474
00475 ?>