AMC Reporting Module: adding rules
[openemr.git] / library / adodb / drivers / adodb-oci8po.inc.php
blob1cccd8efe392627d28ef66d35cd820f690a7d4d7
1 <?php
2 /*
3 V4.20 22 Feb 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.
8 Latest version is available at http://php.weblogs.com/
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 include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
22 class ADODB_oci8po extends ADODB_oci8 {
23 var $databaseType = 'oci8po';
24 var $dataProvider = 'oci8';
25 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
26 var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
28 function ADODB_oci8po()
30 $this->ADODB_oci8();
33 function Param($name)
35 return '?';
38 function Prepare($sql,$cursor=false)
40 $sqlarr = explode('?',$sql);
41 $sql = $sqlarr[0];
42 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
43 $sql .= ':'.($i-1) . $sqlarr[$i];
45 return ADODB_oci8::Prepare($sql,$cursor);
48 // emulate handling of parameters ? ?, replacing with :bind0 :bind1
49 function _query($sql,$inputarr)
51 if (is_array($inputarr)) {
52 $i = 0;
53 if (is_array($sql)) {
54 foreach($inputarr as $v) {
55 $arr['bind'.$i++] = $v;
57 } else {
58 $sqlarr = explode('?',$sql);
59 $sql = $sqlarr[0];
60 foreach($inputarr as $k => $v) {
61 $sql .= ":$k" . $sqlarr[++$i];
65 return ADODB_oci8::_query($sql,$inputarr);
69 /*--------------------------------------------------------------------------------------
70 Class Name: Recordset
71 --------------------------------------------------------------------------------------*/
73 class ADORecordset_oci8po extends ADORecordset_oci8 {
75 var $databaseType = 'oci8po';
77 function ADORecordset_oci8po($queryID,$mode=false)
79 $this->ADORecordset_oci8($queryID,$mode);
82 function Fields($colname)
84 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
86 if (!$this->bind) {
87 $this->bind = array();
88 for ($i=0; $i < $this->_numOfFields; $i++) {
89 $o = $this->FetchField($i);
90 $this->bind[strtoupper($o->name)] = $i;
93 return $this->fields[$this->bind[strtoupper($colname)]];
96 // lowercase field names...
97 function &_FetchField($fieldOffset = -1)
99 $fld = new ADOFieldObject;
100 $fieldOffset += 1;
101 $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset));
102 $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
103 $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
104 if ($fld->type == 'NUMBER') {
105 //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
106 $sc = OCIColumnScale($this->_queryID, $fieldOffset);
107 if ($sc == 0) $fld->type = 'INT';
109 return $fld;
112 // 10% speedup to move MoveNext to child class
113 function MoveNext()
116 if (!$this->EOF) {
117 $this->_currentRow++;
118 if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
119 global $ADODB_ANSI_PADDING_OFF;
121 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
122 if (!empty($ADODB_ANSI_PADDING_OFF)) {
123 foreach($this->fields as $k => $v) {
124 if (is_string($v)) $this->fields[$k] = rtrim($v);
127 return true;
129 $this->EOF = true;
131 return false;
134 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
135 function &GetArrayLimit($nrows,$offset=-1)
137 if ($offset <= 0) return $this->GetArray($nrows);
138 for ($i=1; $i < $offset; $i++)
139 if (!@OCIFetch($this->_queryID)) return array();
141 if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array();
142 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
143 $results = array();
144 $cnt = 0;
145 while (!$this->EOF && $nrows != $cnt) {
146 $results[$cnt++] = $this->fields;
147 $this->MoveNext();
150 return $results;
153 // Create associative array
154 function _updatefields()
156 if (ADODB_ASSOC_CASE == 2) return; // native
158 $arr = array();
159 $lowercase = (ADODB_ASSOC_CASE == 0);
161 foreach($this->fields as $k => $v) {
162 if (is_integer($k)) $arr[$k] = $v;
163 else {
164 if ($lowercase)
165 $arr[strtolower($k)] = $v;
166 else
167 $arr[strtoupper($k)] = $v;
170 $this->fields = $arr;
173 function _fetch()
175 $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
176 if ($ret) {
177 global $ADODB_ANSI_PADDING_OFF;
179 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
180 if (!empty($ADODB_ANSI_PADDING_OFF)) {
181 foreach($this->fields as $k => $v) {
182 if (is_string($v)) $this->fields[$k] = rtrim($v);
186 return $ret;