3 V4.22 15 Apr 2004 (c) 2000-2004 John Lim. All rights reserved.
4 Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence.
7 Set tabs to 4 for best viewing.
9 Latest version is available at http://php.weblogs.com/
11 Informix port by Mitchell T. Young (mitch@youngfamily.org)
13 Further mods by "Samuel CARRIERE" <samuel_carriere@hotmail.com>
17 if (!defined('IFX_SCROLL')) define('IFX_SCROLL',1);
19 class ADODB_informix72 extends ADOConnection {
20 var $databaseType = "informix72";
21 var $dataProvider = "informix";
22 var $replaceQuote = "''"; // string to use to replace quotes
23 var $fmtDate = "'Y-m-d'";
24 var $fmtTimeStamp = "'Y-m-d H:i:s'";
25 var $hasInsertID = true;
26 var $hasAffectedRows = true;
27 var $upperCase = 'upper';
28 var $substr = 'substr';
29 var $metaTablesSQL="select tabname from systables";
31 "select c.colname, c.coltype, c.collength, d.default
32 from syscolumns c, systables t,sysdefaults d
33 where c.tabid=t.tabid and d.tabid=t.tabid and d.colno=c.colno and tabname='%s'";
35 // var $metaColumnsSQL = "select colname, coltype, collength from syscolumns c, systables t where c.tabid=t.tabid and tabname='%s'";
36 var $concat_operator = '||';
38 var $lastQuery = false;
39 var $has_insertid = true;
41 var $_autocommit = true;
42 var $_bindInputArray = true; // set to true if ADOConnection.Execute() permits binding of array parameters.
43 var $sysDate = 'TODAY';
44 var $sysTimeStamp = 'CURRENT';
45 var $cursorType = IFX_SCROLL; // IFX_SCROLL or IFX_HOLD or 0
47 function ADODB_informix72()
49 // alternatively, use older method:
50 //putenv("DBDATE=Y4MD-");
52 // force ISO date format
53 putenv('GL_DATE=%Y-%m-%d');
55 if (function_exists('ifx_byteasvarchar')) {
56 ifx_byteasvarchar(1); // Mode "0" will return a blob id, and mode "1" will return a varchar with text content.
57 ifx_textasvarchar(1); // Mode "0" will return a blob id, and mode "1" will return a varchar with text content.
58 ifx_blobinfile_mode(0); // Mode "0" means save Byte-Blobs in memory, and mode "1" means save Byte-Blobs in a file.
64 if (isset($this->version)) return $this->version;
66 $arr['description'] = $this->GetOne("select DBINFO('version','full') from systables where tabid = 1");
67 $arr['version'] = $this->GetOne("select DBINFO('version','major')||"."||DBINFO('version','minor') from systables where tabid = 1");
68 $this->version = $arr;
74 $sqlca =ifx_getsqlca($this->lastQuery);
75 return @$sqlca["sqlerrd1"];
78 function _affectedrows()
80 if ($this->lastQuery) {
81 return @ifx_affected_rows ($this->lastQuery);
88 if ($this->transOff) return true;
90 $this->Execute('BEGIN');
91 $this->_autocommit = false;
95 function CommitTrans($ok=true)
97 if (!$ok) return $this->RollbackTrans();
98 if ($this->transOff) return true;
99 if ($this->transCnt) $this->transCnt -= 1;
100 $this->Execute('COMMIT');
101 $this->_autocommit = true;
105 function RollbackTrans()
107 if ($this->transOff) return true;
108 if ($this->transCnt) $this->transCnt -= 1;
109 $this->Execute('ROLLBACK');
110 $this->_autocommit = true;
114 function RowLock($tables,$where)
116 if ($this->_autocommit) $this->BeginTrans();
117 return $this->GetOne("select 1 as ignore from $tables where $where for update");
120 /* Returns: the last error message from previous database operation
121 Note: This function is NOT available for Microsoft SQL Server. */
125 if (!empty($this->_logsql)) return $this->_errorMsg;
126 $this->_errorMsg = ifx_errormsg();
127 return $this->_errorMsg;
132 preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse); //!EOS
133 if (is_array($parse) && isset($parse[1])) return (int)$parse[1];
137 function &MetaColumns($table)
139 global $ADODB_FETCH_MODE;
141 if (!empty($this->metaColumnsSQL)) {
142 $save = $ADODB_FETCH_MODE;
143 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
144 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
145 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
146 if (isset($savem)) $this->SetFetchMode($savem);
147 $ADODB_FETCH_MODE = $save;
148 if ($rs === false) return false;
151 while (!$rs->EOF) { //print_r($rs->fields);
152 $fld = new ADOFieldObject();
153 $fld->name = $rs->fields[0];
154 $fld->type = $rs->fields[1];
155 $fld->max_length = $rs->fields[2];
156 if (trim($rs->fields[3]) != "AAAAAA 0") {
157 $fld->has_default = 1;
158 $fld->default_value = $rs->fields[3];
160 $fld->has_default = 0;
163 $retarr[strtolower($fld->name)] = $fld;
174 function &xMetaColumns($table)
176 return ADOConnection::MetaColumns($table,false);
179 function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
181 $type = ($blobtype == 'TEXT') ? 1 : 0;
182 $blobid = ifx_create_blob($type,0,$val);
183 return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blobid));
186 function BlobDecode($blobid)
188 return function_exists('ifx_byteasvarchar') ? $blobid : @ifx_get_blob($blobid);
191 // returns true or false
192 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
194 if (!function_exists('ifx_connect')) return false;
196 $dbs = $argDatabasename . "@" . $argHostname;
197 if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
198 putenv("INFORMIXSERVER=".trim($argHostname));
199 $this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword);
200 if ($this->_connectionID === false) return false;
201 #if ($argDatabasename) return $this->SelectDB($argDatabasename);
205 // returns true or false
206 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
208 if (!function_exists('ifx_connect')) return false;
210 $dbs = $argDatabasename . "@" . $argHostname;
211 putenv("INFORMIXSERVER=".trim($argHostname));
212 $this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword);
213 if ($this->_connectionID === false) return false;
214 #if ($argDatabasename) return $this->SelectDB($argDatabasename);
218 // ifx_do does not accept bind parameters - weird ???
219 function Prepare($sql)
221 $stmt = ifx_prepare($sql);
222 if (!$stmt) return $sql;
223 else return array($sql,$stmt);
226 // returns query ID if successful, otherwise false
227 function _query($sql,$inputarr)
229 global $ADODB_COUNTRECS;
231 // String parameters have to be converted using ifx_create_char
233 foreach($inputarr as $v) {
234 if (gettype($v) == 'string') {
235 $tab[] = ifx_create_char($v);
243 // In case of select statement, we use a scroll cursor in order
244 // to be able to call "move", or "movefirst" statements
245 if (!$ADODB_COUNTRECS && preg_match("/^\s*select/is", $sql)) {
247 $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType, $tab);
250 $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType);
255 $this->lastQuery = ifx_query($sql,$this->_connectionID, $tab);
258 $this->lastQuery = ifx_query($sql,$this->_connectionID);
262 // Following line have been commented because autocommit mode is
263 // not supported by informix SE 7.2
265 //if ($this->_autocommit) ifx_query('COMMIT',$this->_connectionID);
267 return $this->lastQuery;
270 // returns true or false
273 $this->lastQuery = false;
274 return ifx_close($this->_connectionID);
278 /*--------------------------------------------------------------------------------------
279 Class Name: Recordset
280 --------------------------------------------------------------------------------------*/
282 class ADORecordset_informix72 extends ADORecordSet {
284 var $databaseType = "informix72";
286 var $_fieldprops = false;
288 function ADORecordset_informix72($id,$mode=false)
290 if ($mode === false) {
291 global $ADODB_FETCH_MODE;
292 $mode = $ADODB_FETCH_MODE;
294 $this->fetchMode = $mode;
295 return $this->ADORecordSet($id);
298 /* Returns: an object containing field information.
299 Get column information in the Recordset object. fetchField() can be used in order to obtain information about
300 fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
301 fetchField() is retrieved. */
302 function &FetchField($fieldOffset = -1)
304 if (empty($this->_fieldprops)) {
305 $fp = ifx_fieldproperties($this->_queryID);
306 foreach($fp as $k => $v) {
307 $o = new ADOFieldObject;
309 $arr = explode(';', $v); //"SQLTYPE;length;precision;scale;ISNULLABLE"
311 $o->max_length = $arr[1];
312 $this->_fieldprops[] = $o;
313 $o->not_null = $arr[4]=="N";
316 return $this->_fieldprops[$fieldOffset];
321 $this->_numOfRows = -1; // ifx_affected_rows not reliable, only returns estimate -- ($ADODB_COUNTRECS)? ifx_affected_rows($this->_queryID):-1;
322 $this->_numOfFields = ifx_num_fields($this->_queryID);
327 return @ifx_fetch_row($this->_queryID, $row);
332 $this->fields = @ifx_fetch_row($this->_queryID, "LAST");
333 if ($this->fields) $this->EOF = false;
334 $this->_currentRow = -1;
336 if ($this->fetchMode == ADODB_FETCH_NUM) {
337 foreach($this->fields as $v) {
340 $this->fields = $arr;
348 $this->fields = @ifx_fetch_row($this->_queryID, "FIRST");
349 if ($this->fields) $this->EOF = false;
350 $this->_currentRow = 0;
352 if ($this->fetchMode == ADODB_FETCH_NUM) {
353 foreach($this->fields as $v) {
356 $this->fields = $arr;
362 function _fetch($ignore_fields=false)
365 $this->fields = @ifx_fetch_row($this->_queryID);
367 if (!is_array($this->fields)) return false;
369 if ($this->fetchMode == ADODB_FETCH_NUM) {
370 foreach($this->fields as $v) {
373 $this->fields = $arr;
378 /* close() only needs to be called if you are worried about using too much memory while your script
379 is running. All associated result memory for the specified result identifier will automatically be freed. */
382 return ifx_free_result($this->_queryID);