1 | <?php |
---|
2 | /* |
---|
3 | V4.51 29 July 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. |
---|
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) return $this->GetArray($nrows); |
---|
155 | for ($i=1; $i < $offset; $i++) |
---|
156 | if (!@OCIFetch($this->_queryID)) return array(); |
---|
157 | |
---|
158 | if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); |
---|
159 | if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); |
---|
160 | $results = array(); |
---|
161 | $cnt = 0; |
---|
162 | while (!$this->EOF && $nrows != $cnt) { |
---|
163 | $results[$cnt++] = $this->fields; |
---|
164 | $this->MoveNext(); |
---|
165 | } |
---|
166 | |
---|
167 | return $results; |
---|
168 | } |
---|
169 | |
---|
170 | // Create associative array |
---|
171 | function _updatefields() |
---|
172 | { |
---|
173 | if (ADODB_ASSOC_CASE == 2) return; // native |
---|
174 | |
---|
175 | $arr = array(); |
---|
176 | $lowercase = (ADODB_ASSOC_CASE == 0); |
---|
177 | |
---|
178 | foreach($this->fields as $k => $v) { |
---|
179 | if (is_integer($k)) $arr[$k] = $v; |
---|
180 | else { |
---|
181 | if ($lowercase) |
---|
182 | $arr[strtolower($k)] = $v; |
---|
183 | else |
---|
184 | $arr[strtoupper($k)] = $v; |
---|
185 | } |
---|
186 | } |
---|
187 | $this->fields = $arr; |
---|
188 | } |
---|
189 | |
---|
190 | function _fetch() |
---|
191 | { |
---|
192 | $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); |
---|
193 | if ($ret) { |
---|
194 | global $ADODB_ANSI_PADDING_OFF; |
---|
195 | |
---|
196 | if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); |
---|
197 | if (!empty($ADODB_ANSI_PADDING_OFF)) { |
---|
198 | foreach($this->fields as $k => $v) { |
---|
199 | if (is_string($v)) $this->fields[$k] = rtrim($v); |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | return $ret; |
---|
204 | } |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | ?> |
---|