]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / drivers / adodb-oci8po.inc.php
1 <?php
2 /*
3 V4.22 15 Apr 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://php.weblogs.com/
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 include_once(ADODB_DIR . '/drivers/adodb-oci8.inc.php');
21
22 class ADODB_oci8po extends ADODB_oci8
23 {
24     var $databaseType = 'oci8po';
25     var $dataProvider = 'oci8';
26     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
27     var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
28
29     function ADODB_oci8po()
30     {
31         $this->ADODB_oci8();
32     }
33
34     function Param($name)
35     {
36         return '?';
37     }
38
39     function Prepare($sql, $cursor = false)
40     {
41         $sqlarr = explode('?', $sql);
42         $sql = $sqlarr[0];
43         for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
44             $sql .= ':' . ($i - 1) . $sqlarr[$i];
45         }
46         return ADODB_oci8::Prepare($sql, $cursor);
47     }
48
49     // emulate handling of parameters ? ?, replacing with :bind0 :bind1
50     function _query($sql, $inputarr)
51     {
52         if (is_array($inputarr)) {
53             $i = 0;
54             if (is_array($sql)) {
55                 foreach ($inputarr as $v) {
56                     $arr['bind' . $i++] = $v;
57                 }
58             } else {
59                 $sqlarr = explode('?', $sql);
60                 $sql = $sqlarr[0];
61                 foreach ($inputarr as $k => $v) {
62                     $sql .= ":$k" . $sqlarr[++$i];
63                 }
64             }
65         }
66         return ADODB_oci8::_query($sql, $inputarr);
67     }
68 }
69
70 /*--------------------------------------------------------------------------------------
71          Class Name: Recordset
72 --------------------------------------------------------------------------------------*/
73
74 class ADORecordset_oci8po extends ADORecordset_oci8
75 {
76
77     var $databaseType = 'oci8po';
78
79     function ADORecordset_oci8po($queryID, $mode = false)
80     {
81         $this->ADORecordset_oci8($queryID, $mode);
82     }
83
84     function Fields($colname)
85     {
86         if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
87
88         if (!$this->bind) {
89             $this->bind = array();
90             for ($i = 0; $i < $this->_numOfFields; $i++) {
91                 $o = $this->FetchField($i);
92                 $this->bind[strtoupper($o->name)] = $i;
93             }
94         }
95         return $this->fields[$this->bind[strtoupper($colname)]];
96     }
97
98     // lowercase field names...
99     function &_FetchField($fieldOffset = -1)
100     {
101         $fld = new ADOFieldObject;
102         $fieldOffset += 1;
103         $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset));
104         $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
105         $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
106         if ($fld->type == 'NUMBER') {
107             //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
108             $sc = OCIColumnScale($this->_queryID, $fieldOffset);
109             if ($sc == 0) $fld->type = 'INT';
110         }
111         return $fld;
112     }
113
114     // 10% speedup to move MoveNext to child class
115     function MoveNext()
116     {
117
118         if (!$this->EOF) {
119             $this->_currentRow++;
120             if (@OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode)) {
121                 global $ADODB_ANSI_PADDING_OFF;
122
123                 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
124                 if (!empty($ADODB_ANSI_PADDING_OFF)) {
125                     foreach ($this->fields as $k => $v) {
126                         if (is_string($v)) $this->fields[$k] = rtrim($v);
127                     }
128                 }
129                 return true;
130             }
131             $this->EOF = true;
132         }
133         return false;
134     }
135
136     /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
137     function &GetArrayLimit($nrows, $offset = -1)
138     {
139         if ($offset <= 0) return $this->GetArray($nrows);
140         for ($i = 1; $i < $offset; $i++)
141             if (!@OCIFetch($this->_queryID)) return array();
142
143         if (!@OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode)) return array();
144         if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
145         $results = array();
146         $cnt = 0;
147         while (!$this->EOF && $nrows != $cnt) {
148             $results[$cnt++] = $this->fields;
149             $this->MoveNext();
150         }
151
152         return $results;
153     }
154
155     // Create associative array
156     function _updatefields()
157     {
158         if (ADODB_ASSOC_CASE == 2) return; // native
159
160         $arr = array();
161         $lowercase = (ADODB_ASSOC_CASE == 0);
162
163         foreach ($this->fields as $k => $v) {
164             if (is_integer($k)) $arr[$k] = $v;
165             else {
166                 if ($lowercase)
167                     $arr[strtolower($k)] = $v;
168                 else
169                     $arr[strtoupper($k)] = $v;
170             }
171         }
172         $this->fields = $arr;
173     }
174
175     function _fetch()
176     {
177         $ret = @OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode);
178         if ($ret) {
179             global $ADODB_ANSI_PADDING_OFF;
180
181             if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
182             if (!empty($ADODB_ANSI_PADDING_OFF)) {
183                 foreach ($this->fields as $k => $v) {
184                     if (is_string($v)) $this->fields[$k] = rtrim($v);
185                 }
186             }
187         }
188         return $ret;
189     }
190
191 }