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.
8 Latest version is available at http://php.weblogs.com/
10 Portable version of oci8 driver, to make it more similar to other database drivers.
11 The main differences are
13 1. that the OCI_ASSOC names are in lowercase instead of uppercase.
14 2. bind variables are mapped using ? instead of :<bindvar>
16 Should some emulation of RecordCount() be implemented?
20 include_once(ADODB_DIR . '/drivers/adodb-oci8.inc.php');
22 class ADODB_oci8po extends ADODB_oci8
24 var $databaseType = 'oci8po';
25 var $dataProvider = 'oci8';
26 var $metaColumnsSQL = "select lower(cname),coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net
27 var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
29 function ADODB_oci8po()
39 function Prepare($sql, $cursor = false)
41 $sqlarr = explode('?', $sql);
43 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
44 $sql .= ':' . ($i - 1) . $sqlarr[$i];
46 return ADODB_oci8::Prepare($sql, $cursor);
49 // emulate handling of parameters ? ?, replacing with :bind0 :bind1
50 function _query($sql, $inputarr)
52 if (is_array($inputarr)) {
55 foreach ($inputarr as $v) {
56 $arr['bind' . $i++] = $v;
59 $sqlarr = explode('?', $sql);
61 foreach ($inputarr as $k => $v) {
62 $sql .= ":$k" . $sqlarr[++$i];
66 return ADODB_oci8::_query($sql, $inputarr);
70 /*--------------------------------------------------------------------------------------
72 --------------------------------------------------------------------------------------*/
74 class ADORecordset_oci8po extends ADORecordset_oci8
77 var $databaseType = 'oci8po';
79 function ADORecordset_oci8po($queryID, $mode = false)
81 $this->ADORecordset_oci8($queryID, $mode);
84 function Fields($colname)
86 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
89 $this->bind = array();
90 for ($i = 0; $i < $this->_numOfFields; $i++) {
91 $o = $this->FetchField($i);
92 $this->bind[strtoupper($o->name)] = $i;
95 return $this->fields[$this->bind[strtoupper($colname)]];
98 // lowercase field names...
99 function &_FetchField($fieldOffset = -1)
101 $fld = new ADOFieldObject;
103 $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset));
104 $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
105 $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
106 if ($fld->type == 'NUMBER') {
107 //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
108 $sc = OCIColumnScale($this->_queryID, $fieldOffset);
109 if ($sc == 0) $fld->type = 'INT';
114 // 10% speedup to move MoveNext to child class
119 $this->_currentRow++;
120 if (@OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode)) {
121 global $ADODB_ANSI_PADDING_OFF;
123 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
124 if (!empty($ADODB_ANSI_PADDING_OFF)) {
125 foreach ($this->fields as $k => $v) {
126 if (is_string($v)) $this->fields[$k] = rtrim($v);
136 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
137 function &GetArrayLimit($nrows, $offset = -1)
139 if ($offset <= 0) return $this->GetArray($nrows);
140 for ($i = 1; $i < $offset; $i++)
141 if (!@OCIFetch($this->_queryID)) return array();
143 if (!@OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode)) return array();
144 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
147 while (!$this->EOF && $nrows != $cnt) {
148 $results[$cnt++] = $this->fields;
155 // Create associative array
156 function _updatefields()
158 if (ADODB_ASSOC_CASE == 2) return; // native
161 $lowercase = (ADODB_ASSOC_CASE == 0);
163 foreach ($this->fields as $k => $v) {
164 if (is_integer($k)) $arr[$k] = $v;
167 $arr[strtolower($k)] = $v;
169 $arr[strtoupper($k)] = $v;
172 $this->fields = $arr;
177 $ret = @OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode);
179 global $ADODB_ANSI_PADDING_OFF;
181 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
182 if (!empty($ADODB_ANSI_PADDING_OFF)) {
183 foreach ($this->fields as $k => $v) {
184 if (is_string($v)) $this->fields[$k] = rtrim($v);