3 V5.16 26 Mar 2012 (c) 2000-2012 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://adodb.sourceforge.net
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 // security - hide paths
21 if (!defined('ADODB_DIR')) die();
23 include_once(ADODB_DIR
.'/drivers/adodb-oci8.inc.php');
25 class ADODB_oci8po
extends ADODB_oci8
{
26 var $databaseType = 'oci8po';
27 var $dataProvider = 'oci8';
28 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
29 var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
31 function ADODB_oci8po()
33 $this->_hasOCIFetchStatement
= ADODB_PHPVER
>= 0x4200;
34 # oci8po does not support adodb extension: adodb_movenext()
37 function Param($name,$type='C')
42 function Prepare($sql,$cursor=false)
44 $sqlarr = explode('?',$sql);
46 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++
) {
47 $sql .= ':'.($i-1) . $sqlarr[$i];
49 return ADODB_oci8
::Prepare($sql,$cursor);
52 function Execute($sql,$inputarr=false)
54 return ADOConnection
::Execute($sql,$inputarr);
57 // emulate handling of parameters ? ?, replacing with :bind0 :bind1
58 function _query($sql,$inputarr=false)
60 if (is_array($inputarr)) {
63 foreach($inputarr as $v) {
64 $arr['bind'.$i++
] = $v;
67 $sqlarr = explode('?',$sql);
69 foreach($inputarr as $k => $v) {
70 $sql .= ":$k" . $sqlarr[++
$i];
74 return ADODB_oci8
::_query($sql,$inputarr);
78 /*--------------------------------------------------------------------------------------
80 --------------------------------------------------------------------------------------*/
82 class ADORecordset_oci8po
extends ADORecordset_oci8
{
84 var $databaseType = 'oci8po';
86 function ADORecordset_oci8po($queryID,$mode=false)
88 $this->ADORecordset_oci8($queryID,$mode);
91 function Fields($colname)
93 if ($this->fetchMode
& OCI_ASSOC
) return $this->fields
[$colname];
96 $this->bind
= array();
97 for ($i=0; $i < $this->_numOfFields
; $i++
) {
98 $o = $this->FetchField($i);
99 $this->bind
[strtoupper($o->name
)] = $i;
102 return $this->fields
[$this->bind
[strtoupper($colname)]];
105 // lowercase field names...
106 function _FetchField($fieldOffset = -1)
108 $fld = new ADOFieldObject
;
110 $fld->name
= OCIcolumnname($this->_queryID
, $fieldOffset);
111 if (ADODB_ASSOC_CASE
== 0) $fld->name
= strtolower($fld->name
);
112 $fld->type
= OCIcolumntype($this->_queryID
, $fieldOffset);
113 $fld->max_length
= OCIcolumnsize($this->_queryID
, $fieldOffset);
114 if ($fld->type
== 'NUMBER') {
115 //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
116 $sc = OCIColumnScale($this->_queryID
, $fieldOffset);
117 if ($sc == 0) $fld->type
= 'INT';
124 if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
125 $this->_currentRow += 1;
129 $this->_currentRow += 1;
135 // 10% speedup to move MoveNext to child class
138 if(@OCIfetchinto
($this->_queryID
,$this->fields
,$this->fetchMode
)) {
139 global $ADODB_ANSI_PADDING_OFF;
140 $this->_currentRow++
;
142 if ($this->fetchMode
& OCI_ASSOC
) $this->_updatefields();
143 if (!empty($ADODB_ANSI_PADDING_OFF)) {
144 foreach($this->fields
as $k => $v) {
145 if (is_string($v)) $this->fields
[$k] = rtrim($v);
152 $this->_currentRow++
;
157 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
158 function GetArrayLimit($nrows,$offset=-1)
161 $arr = $this->GetArray($nrows);
164 for ($i=1; $i < $offset; $i++
)
165 if (!@OCIFetch
($this->_queryID
)) {
169 if (!@OCIfetchinto
($this->_queryID
,$this->fields
,$this->fetchMode
)) {
173 if ($this->fetchMode
& OCI_ASSOC
) $this->_updatefields();
176 while (!$this->EOF
&& $nrows != $cnt) {
177 $results[$cnt++
] = $this->fields
;
184 // Create associative array
185 function _updatefields()
187 if (ADODB_ASSOC_CASE
== 2) return; // native
190 $lowercase = (ADODB_ASSOC_CASE
== 0);
192 foreach($this->fields
as $k => $v) {
193 if (is_integer($k)) $arr[$k] = $v;
196 $arr[strtolower($k)] = $v;
198 $arr[strtoupper($k)] = $v;
201 $this->fields
= $arr;
206 $ret = @OCIfetchinto
($this->_queryID
,$this->fields
,$this->fetchMode
);
208 global $ADODB_ANSI_PADDING_OFF;
210 if ($this->fetchMode
& OCI_ASSOC
) $this->_updatefields();
211 if (!empty($ADODB_ANSI_PADDING_OFF)) {
212 foreach($this->fields
as $k => $v) {
213 if (is_string($v)) $this->fields
[$k] = rtrim($v);