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;
76 $sqlca =ifx_getsqlca($this->lastQuery);
77 return @$sqlca["sqlerrd1"];
80 function _affectedrows()
82 if ($this->lastQuery) {
83 return @ifx_affected_rows ($this->lastQuery);
90 if ($this->transOff) return true;
92 $this->Execute('BEGIN');
93 $this->_autocommit = false;
97 function CommitTrans($ok=true)
99 if (!$ok) return $this->RollbackTrans();
100 if ($this->transOff) return true;
101 if ($this->transCnt) $this->transCnt -= 1;
102 $this->Execute('COMMIT');
103 $this->_autocommit = true;
107 function RollbackTrans()
109 if ($this->transOff) return true;
110 if ($this->transCnt) $this->transCnt -= 1;
111 $this->Execute('ROLLBACK');
112 $this->_autocommit = true;
116 function RowLock($tables,$where)
118 if ($this->_autocommit) $this->BeginTrans();
119 return $this->GetOne("select 1 as ignore from $tables where $where for update");
122 /* Returns: the last error message from previous database operation
123 Note: This function is NOT available for Microsoft SQL Server. */
127 if (!empty($this->_logsql)) return $this->_errorMsg;
128 $this->_errorMsg = ifx_errormsg();
129 return $this->_errorMsg;
134 preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse); //!EOS
135 if (is_array($parse) && isset($parse[1])) return (int)$parse[1];
140 function &MetaColumns($table)
142 global $ADODB_FETCH_MODE;
144 if (!empty($this->metaColumnsSQL)) {
145 $save = $ADODB_FETCH_MODE;
146 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
147 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
148 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
149 if (isset($savem)) $this->SetFetchMode($savem);
150 $ADODB_FETCH_MODE = $save;
151 if ($rs === false) return false;
154 while (!$rs->EOF) { //print_r($rs->fields);
155 $fld = new ADOFieldObject();
156 $fld->name = $rs->fields[0];
157 $fld->type = $rs->fields[1];
158 $fld->max_length = $rs->fields[2];
159 if (trim($rs->fields[3]) != "AAAAAA 0") {
160 $fld->has_default = 1;
161 $fld->default_value = $rs->fields[3];
163 $fld->has_default = 0;
166 $retarr[strtolower($fld->name)] = $fld;
177 function &xMetaColumns($table)
179 return ADOConnection::MetaColumns($table,false);
182 function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
184 $type = ($blobtype == 'TEXT') ? 1 : 0;
185 $blobid = ifx_create_blob($type,0,$val);
186 return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blobid));
189 function BlobDecode($blobid)
191 return function_exists('ifx_byteasvarchar') ? $blobid : @ifx_get_blob($blobid);
194 // returns true or false
195 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
197 if (!function_exists('ifx_connect')) return false;
199 $dbs = $argDatabasename . "@" . $argHostname;
200 if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
201 putenv("INFORMIXSERVER=".trim($argHostname));
202 $this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword);
203 if ($this->_connectionID === false) return false;
204 #if ($argDatabasename) return $this->SelectDB($argDatabasename);
208 // returns true or false
209 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
211 if (!function_exists('ifx_connect')) return false;
213 $dbs = $argDatabasename . "@" . $argHostname;
214 putenv("INFORMIXSERVER=".trim($argHostname));
215 $this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword);
216 if ($this->_connectionID === false) return false;
217 #if ($argDatabasename) return $this->SelectDB($argDatabasename);
221 // ifx_do does not accept bind parameters - weird ???
222 function Prepare($sql)
224 $stmt = ifx_prepare($sql);
225 if (!$stmt) return $sql;
226 else return array($sql,$stmt);
229 // returns query ID if successful, otherwise false
230 function _query($sql,$inputarr)
232 global $ADODB_COUNTRECS;
234 // String parameters have to be converted using ifx_create_char
236 foreach($inputarr as $v) {
237 if (gettype($v) == 'string') {
238 $tab[] = ifx_create_char($v);
246 // In case of select statement, we use a scroll cursor in order
247 // to be able to call "move", or "movefirst" statements
248 if (!$ADODB_COUNTRECS && preg_match("/^\s*select/is", $sql)) {
250 $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType, $tab);
253 $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType);
258 $this->lastQuery = ifx_query($sql,$this->_connectionID, $tab);
261 $this->lastQuery = ifx_query($sql,$this->_connectionID);
265 // Following line have been commented because autocommit mode is
266 // not supported by informix SE 7.2
268 //if ($this->_autocommit) ifx_query('COMMIT',$this->_connectionID);
270 return $this->lastQuery;
273 // returns true or false
276 $this->lastQuery = false;
277 return ifx_close($this->_connectionID);
282 /*--------------------------------------------------------------------------------------
283 Class Name: Recordset
284 --------------------------------------------------------------------------------------*/
286 class ADORecordset_informix72 extends ADORecordSet {
288 var $databaseType = "informix72";
290 var $_fieldprops = false;
292 function ADORecordset_informix72($id,$mode=false)
294 if ($mode === false) {
295 global $ADODB_FETCH_MODE;
296 $mode = $ADODB_FETCH_MODE;
298 $this->fetchMode = $mode;
299 return $this->ADORecordSet($id);
304 /* Returns: an object containing field information.
305 Get column information in the Recordset object. fetchField() can be used in order to obtain information about
306 fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
307 fetchField() is retrieved. */
308 function &FetchField($fieldOffset = -1)
310 if (empty($this->_fieldprops)) {
311 $fp = ifx_fieldproperties($this->_queryID);
312 foreach($fp as $k => $v) {
313 $o = new ADOFieldObject;
315 $arr = explode(';', $v); //"SQLTYPE;length;precision;scale;ISNULLABLE"
317 $o->max_length = $arr[1];
318 $this->_fieldprops[] = $o;
319 $o->not_null = $arr[4]=="N";
322 return $this->_fieldprops[$fieldOffset];
327 $this->_numOfRows = -1; // ifx_affected_rows not reliable, only returns estimate -- ($ADODB_COUNTRECS)? ifx_affected_rows($this->_queryID):-1;
328 $this->_numOfFields = ifx_num_fields($this->_queryID);
333 return @ifx_fetch_row($this->_queryID, $row);
338 $this->fields = @ifx_fetch_row($this->_queryID, "LAST");
339 if ($this->fields) $this->EOF = false;
340 $this->_currentRow = -1;
342 if ($this->fetchMode == ADODB_FETCH_NUM) {
343 foreach($this->fields as $v) {
346 $this->fields = $arr;
354 $this->fields = @ifx_fetch_row($this->_queryID, "FIRST");
355 if ($this->fields) $this->EOF = false;
356 $this->_currentRow = 0;
358 if ($this->fetchMode == ADODB_FETCH_NUM) {
359 foreach($this->fields as $v) {
362 $this->fields = $arr;
368 function _fetch($ignore_fields=false)
371 $this->fields = @ifx_fetch_row($this->_queryID);
373 if (!is_array($this->fields)) return false;
375 if ($this->fetchMode == ADODB_FETCH_NUM) {
376 foreach($this->fields as $v) {
379 $this->fields = $arr;
384 /* close() only needs to be called if you are worried about using too much memory while your script
385 is running. All associated result memory for the specified result identifier will automatically be freed. */
388 return ifx_free_result($this->_queryID);