MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / lib / adodb / drivers / adodb-oci8po.inc.php
blob2432f395a1a9fd9485b2ef6f1eaa29dbddf2baef
1 <?php
2 /*
3 V4.94 23 Jan 2007 (c) 2000-2007 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)
39 return '?';
42 function Prepare($sql,$cursor=false)
44 $sqlarr = explode('?',$sql);
45 $sql = $sqlarr[0];
46 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
47 $sql .= ':'.($i-1) . $sqlarr[$i];
49 return ADODB_oci8::Prepare($sql,$cursor);
52 // emulate handling of parameters ? ?, replacing with :bind0 :bind1
53 function _query($sql,$inputarr)
55 if (is_array($inputarr)) {
56 $i = 0;
57 if (is_array($sql)) {
58 foreach($inputarr as $v) {
59 $arr['bind'.$i++] = $v;
61 } else {
62 $sqlarr = explode('?',$sql);
63 $sql = $sqlarr[0];
64 foreach($inputarr as $k => $v) {
65 $sql .= ":$k" . $sqlarr[++$i];
69 return ADODB_oci8::_query($sql,$inputarr);
73 /*--------------------------------------------------------------------------------------
74 Class Name: Recordset
75 --------------------------------------------------------------------------------------*/
77 class ADORecordset_oci8po extends ADORecordset_oci8 {
79 var $databaseType = 'oci8po';
81 function ADORecordset_oci8po($queryID,$mode=false)
83 $this->ADORecordset_oci8($queryID,$mode);
86 function Fields($colname)
88 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
90 if (!$this->bind) {
91 $this->bind = array();
92 for ($i=0; $i < $this->_numOfFields; $i++) {
93 $o = $this->FetchField($i);
94 $this->bind[strtoupper($o->name)] = $i;
97 return $this->fields[$this->bind[strtoupper($colname)]];
100 // lowercase field names...
101 function &_FetchField($fieldOffset = -1)
103 $fld = new ADOFieldObject;
104 $fieldOffset += 1;
105 $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset));
106 $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
107 $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
108 if ($fld->type == 'NUMBER') {
109 //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
110 $sc = OCIColumnScale($this->_queryID, $fieldOffset);
111 if ($sc == 0) $fld->type = 'INT';
113 return $fld;
116 function MoveNext()
118 if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
119 $this->_currentRow += 1;
120 return true;
122 if (!$this->EOF) {
123 $this->_currentRow += 1;
124 $this->EOF = true;
126 return false;
129 // 10% speedup to move MoveNext to child class
130 function MoveNext()
132 if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
133 global $ADODB_ANSI_PADDING_OFF;
134 $this->_currentRow++;
136 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
137 if (!empty($ADODB_ANSI_PADDING_OFF)) {
138 foreach($this->fields as $k => $v) {
139 if (is_string($v)) $this->fields[$k] = rtrim($v);
142 return true;
144 if (!$this->EOF) {
145 $this->EOF = true;
146 $this->_currentRow++;
148 return false;
151 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
152 function &GetArrayLimit($nrows,$offset=-1)
154 if ($offset <= 0) {
155 $arr = $this->GetArray($nrows);
156 return $arr;
158 for ($i=1; $i < $offset; $i++)
159 if (!@OCIFetch($this->_queryID)) {
160 $arr = array();
161 return $arr;
163 if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
164 $arr = array();
165 return $arr;
167 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
168 $results = array();
169 $cnt = 0;
170 while (!$this->EOF && $nrows != $cnt) {
171 $results[$cnt++] = $this->fields;
172 $this->MoveNext();
175 return $results;
178 // Create associative array
179 function _updatefields()
181 if (ADODB_ASSOC_CASE == 2) return; // native
183 $arr = array();
184 $lowercase = (ADODB_ASSOC_CASE == 0);
186 foreach($this->fields as $k => $v) {
187 if (is_integer($k)) $arr[$k] = $v;
188 else {
189 if ($lowercase)
190 $arr[strtolower($k)] = $v;
191 else
192 $arr[strtoupper($k)] = $v;
195 $this->fields = $arr;
198 function _fetch()
200 $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
201 if ($ret) {
202 global $ADODB_ANSI_PADDING_OFF;
204 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
205 if (!empty($ADODB_ANSI_PADDING_OFF)) {
206 foreach($this->fields as $k => $v) {
207 if (is_string($v)) $this->fields[$k] = rtrim($v);
211 return $ret;