3 @version v5.20.3 01-Jan-2016
4 @copyright (c) 2000-2013 John Lim. All rights reserved.
5 @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
6 Released under both BSD license and Lesser GPL library license.
7 Whenever there is any discrepancy between the two licenses,
8 the BSD license will take precedence.
10 Latest version is available at http://adodb.sourceforge.net
12 Portable version of oci8 driver, to make it more similar to other database drivers.
13 The main differences are
15 1. that the OCI_ASSOC names are in lowercase instead of uppercase.
16 2. bind variables are mapped using ? instead of :<bindvar>
18 Should some emulation of RecordCount() be implemented?
22 // security - hide paths
23 if (!defined('ADODB_DIR')) die();
25 include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
27 class ADODB_oci8po extends ADODB_oci8 {
28 var $databaseType = 'oci8po';
29 var $dataProvider = 'oci8';
30 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
31 var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
33 function __construct()
35 $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;
36 # oci8po does not support adodb extension: adodb_movenext()
39 function Param($name,$type='C')
44 function Prepare($sql,$cursor=false)
46 $sqlarr = explode('?',$sql);
48 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
49 $sql .= ':'.($i-1) . $sqlarr[$i];
51 return ADODB_oci8::Prepare($sql,$cursor);
54 function Execute($sql,$inputarr=false)
56 return ADOConnection::Execute($sql,$inputarr);
59 // emulate handling of parameters ? ?, replacing with :bind0 :bind1
60 function _query($sql,$inputarr=false)
62 if (is_array($inputarr)) {
65 foreach($inputarr as $v) {
66 $arr['bind'.$i++] = $v;
69 // Need to identify if the ? is inside a quoted string, and if
70 // so not use it as a bind variable
71 preg_match_all('/".*\??"|\'.*\?.*?\'/', $sql, $matches);
72 foreach($matches[0] as $qmMatch){
73 $qmReplace = str_replace('?', '-QUESTIONMARK-', $qmMatch);
74 $sql = str_replace($qmMatch, $qmReplace, $sql);
77 $sqlarr = explode('?',$sql);
80 foreach($inputarr as $k => $v) {
81 $sql .= ":$k" . $sqlarr[++$i];
84 $sql = str_replace('-QUESTIONMARK-', '?', $sql);
87 return ADODB_oci8::_query($sql,$inputarr);
91 /*--------------------------------------------------------------------------------------
93 --------------------------------------------------------------------------------------*/
95 class ADORecordset_oci8po extends ADORecordset_oci8 {
97 var $databaseType = 'oci8po';
99 function __construct($queryID,$mode=false)
101 parent::__construct($queryID,$mode);
104 function Fields($colname)
106 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
109 $this->bind = array();
110 for ($i=0; $i < $this->_numOfFields; $i++) {
111 $o = $this->FetchField($i);
112 $this->bind[strtoupper($o->name)] = $i;
115 return $this->fields[$this->bind[strtoupper($colname)]];
118 // lowercase field names...
119 function _FetchField($fieldOffset = -1)
121 $fld = new ADOFieldObject;
123 $fld->name = OCIcolumnname($this->_queryID, $fieldOffset);
124 if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_LOWER) {
125 $fld->name = strtolower($fld->name);
127 $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
128 $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
129 if ($fld->type == 'NUMBER') {
130 $sc = OCIColumnScale($this->_queryID, $fieldOffset);
138 // 10% speedup to move MoveNext to child class
141 $ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
143 global $ADODB_ANSI_PADDING_OFF;
144 $this->fields = $ret;
145 $this->_currentRow++;
146 $this->_updatefields();
148 if (!empty($ADODB_ANSI_PADDING_OFF)) {
149 foreach($this->fields as $k => $v) {
150 if (is_string($v)) $this->fields[$k] = rtrim($v);
157 $this->_currentRow++;
162 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
163 function GetArrayLimit($nrows,$offset=-1)
166 $arr = $this->GetArray($nrows);
169 for ($i=1; $i < $offset; $i++)
170 if (!@OCIFetch($this->_queryID)) {
174 $ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
175 if ($ret === false) {
179 $this->fields = $ret;
180 $this->_updatefields();
183 while (!$this->EOF && $nrows != $cnt) {
184 $results[$cnt++] = $this->fields;
193 global $ADODB_ANSI_PADDING_OFF;
195 $ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
197 $this->fields = $ret;
198 $this->_updatefields();
200 if (!empty($ADODB_ANSI_PADDING_OFF)) {
201 foreach($this->fields as $k => $v) {
202 if (is_string($v)) $this->fields[$k] = rtrim($v);
206 return $ret !== false;