dc75c79456d52418dff4ab0851d4ec7d452ed37c
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-oci8po.inc.php
1 <?php
2 /*
3 V4.93 10 Oct 2006 (c) 2000-2006 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
8 Latest version is available at http://adodb.sourceforge.net
9
10 Portable version of oci8 driver, to make it more similar to other database drivers.
11 The main differences are
12
13 1. that the OCI_ASSOC names are in lowercase instead of uppercase.
14 2. bind variables are mapped using ? instead of :<bindvar>
15
16 Should some emulation of RecordCount() be implemented?
17
18 */
19
20 // security - hide paths
21 if (!defined('ADODB_DIR')) die();
22
23 include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
24
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')";
30
31 function ADODB_oci8po()
32 {
33 $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;
34 # oci8po does not support adodb extension: adodb_movenext()
35 }
36
37 function Param($name)
38 {
39 return '?';
40 }
41
42 function Prepare($sql,$cursor=false)
43 {
44 $sqlarr = explode('?',$sql);
45 $sql = $sqlarr[0];
46 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
47 $sql .= ':'.($i-1) . $sqlarr[$i];
48 }
49 return ADODB_oci8::Prepare($sql,$cursor);
50 }
51
52 // emulate handling of parameters ? ?, replacing with :bind0 :bind1
53 function _query($sql,$inputarr)
54 {
55 if (is_array($inputarr)) {
56 $i = 0;
57 if (is_array($sql)) {
58 foreach($inputarr as $v) {
59 $arr['bind'.$i++] = $v;
60 }
61 } else {
62 $sqlarr = explode('?',$sql);
63 $sql = $sqlarr[0];
64 foreach($inputarr as $k => $v) {
65 $sql .= ":$k" . $sqlarr[++$i];
66 }
67 }
68 }
69 return ADODB_oci8::_query($sql,$inputarr);
70 }
71 }
72
73 /*--------------------------------------------------------------------------------------
74 Class Name: Recordset
75 --------------------------------------------------------------------------------------*/
76
77 class ADORecordset_oci8po extends ADORecordset_oci8 {
78
79 var $databaseType = 'oci8po';
80
81 function ADORecordset_oci8po($queryID,$mode=false)
82 {
83 $this->ADORecordset_oci8($queryID,$mode);
84 }
85
86 function Fields($colname)
87 {
88 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
89
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;
95 }
96 }
97 return $this->fields[$this->bind[strtoupper($colname)]];
98 }
99
100 // lowercase field names...
101 function &_FetchField($fieldOffset = -1)
102 {
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';
112 }
113 return $fld;
114 }
115 /*
116 function MoveNext()
117 {
118 if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
119 $this->_currentRow += 1;
120 return true;
121 }
122 if (!$this->EOF) {
123 $this->_currentRow += 1;
124 $this->EOF = true;
125 }
126 return false;
127 }*/
128
129 // 10% speedup to move MoveNext to child class
130 function MoveNext()
131 {
132 if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
133 global $ADODB_ANSI_PADDING_OFF;
134 $this->_currentRow++;
135
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);
140 }
141 }
142 return true;
143 }
144 if (!$this->EOF) {
145 $this->EOF = true;
146 $this->_currentRow++;
147 }
148 return false;
149 }
150
151 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
152 function &GetArrayLimit($nrows,$offset=-1)
153 {
154 if ($offset <= 0) {
155 $arr = $this->GetArray($nrows);
156 return $arr;
157 }
158 for ($i=1; $i < $offset; $i++)
159 if (!@OCIFetch($this->_queryID)) {
160 $arr = array();
161 return $arr;
162 }
163 if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
164 $arr = array();
165 return $arr;
166 }
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();
173 }
174
175 return $results;
176 }
177
178 // Create associative array
179 function _updatefields()
180 {
181 if (ADODB_ASSOC_CASE == 2) return; // native
182
183 $arr = array();
184 $lowercase = (ADODB_ASSOC_CASE == 0);
185
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;
193 }
194 }
195 $this->fields = $arr;
196 }
197
198 function _fetch()
199 {
200 $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
201 if ($ret) {
202 global $ADODB_ANSI_PADDING_OFF;
203
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);
208 }
209 }
210 }
211 return $ret;
212 }
213
214 }
215
216
217 ?>