|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 V5.14 8 Sept 2011 (c) 2000-2011 John Lim. All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. 00007 00008 Latest version is available at http://adodb.sourceforge.net 00009 00010 Portable version of oci8 driver, to make it more similar to other database drivers. 00011 The main differences are 00012 00013 1. that the OCI_ASSOC names are in lowercase instead of uppercase. 00014 2. bind variables are mapped using ? instead of :<bindvar> 00015 00016 Should some emulation of RecordCount() be implemented? 00017 00018 */ 00019 00020 // security - hide paths 00021 if (!defined('ADODB_DIR')) die(); 00022 00023 include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php'); 00024 00025 class ADODB_oci8po extends ADODB_oci8 { 00026 var $databaseType = 'oci8po'; 00027 var $dataProvider = 'oci8'; 00028 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 00029 var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')"; 00030 00031 function ADODB_oci8po() 00032 { 00033 $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200; 00034 # oci8po does not support adodb extension: adodb_movenext() 00035 } 00036 00037 function Param($name) 00038 { 00039 return '?'; 00040 } 00041 00042 function Prepare($sql,$cursor=false) 00043 { 00044 $sqlarr = explode('?',$sql); 00045 $sql = $sqlarr[0]; 00046 for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { 00047 $sql .= ':'.($i-1) . $sqlarr[$i]; 00048 } 00049 return ADODB_oci8::Prepare($sql,$cursor); 00050 } 00051 00052 function Execute($sql,$inputarr=false) 00053 { 00054 return ADOConnection::Execute($sql,$inputarr); 00055 } 00056 00057 // emulate handling of parameters ? ?, replacing with :bind0 :bind1 00058 function _query($sql,$inputarr=false) 00059 { 00060 if (is_array($inputarr)) { 00061 $i = 0; 00062 if (is_array($sql)) { 00063 foreach($inputarr as $v) { 00064 $arr['bind'.$i++] = $v; 00065 } 00066 } else { 00067 $sqlarr = explode('?',$sql); 00068 $sql = $sqlarr[0]; 00069 foreach($inputarr as $k => $v) { 00070 $sql .= ":$k" . $sqlarr[++$i]; 00071 } 00072 } 00073 } 00074 return ADODB_oci8::_query($sql,$inputarr); 00075 } 00076 } 00077 00078 /*-------------------------------------------------------------------------------------- 00079 Class Name: Recordset 00080 --------------------------------------------------------------------------------------*/ 00081 00082 class ADORecordset_oci8po extends ADORecordset_oci8 { 00083 00084 var $databaseType = 'oci8po'; 00085 00086 function ADORecordset_oci8po($queryID,$mode=false) 00087 { 00088 $this->ADORecordset_oci8($queryID,$mode); 00089 } 00090 00091 function Fields($colname) 00092 { 00093 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname]; 00094 00095 if (!$this->bind) { 00096 $this->bind = array(); 00097 for ($i=0; $i < $this->_numOfFields; $i++) { 00098 $o = $this->FetchField($i); 00099 $this->bind[strtoupper($o->name)] = $i; 00100 } 00101 } 00102 return $this->fields[$this->bind[strtoupper($colname)]]; 00103 } 00104 00105 // lowercase field names... 00106 function _FetchField($fieldOffset = -1) 00107 { 00108 $fld = new ADOFieldObject; 00109 $fieldOffset += 1; 00110 $fld->name = OCIcolumnname($this->_queryID, $fieldOffset); 00111 if (ADODB_ASSOC_CASE == 0) $fld->name = strtolower($fld->name); 00112 $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); 00113 $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); 00114 if ($fld->type == 'NUMBER') { 00115 //$p = OCIColumnPrecision($this->_queryID, $fieldOffset); 00116 $sc = OCIColumnScale($this->_queryID, $fieldOffset); 00117 if ($sc == 0) $fld->type = 'INT'; 00118 } 00119 return $fld; 00120 } 00121 /* 00122 function MoveNext() 00123 { 00124 if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { 00125 $this->_currentRow += 1; 00126 return true; 00127 } 00128 if (!$this->EOF) { 00129 $this->_currentRow += 1; 00130 $this->EOF = true; 00131 } 00132 return false; 00133 }*/ 00134 00135 // 10% speedup to move MoveNext to child class 00136 function MoveNext() 00137 { 00138 if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { 00139 global $ADODB_ANSI_PADDING_OFF; 00140 $this->_currentRow++; 00141 00142 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); 00143 if (!empty($ADODB_ANSI_PADDING_OFF)) { 00144 foreach($this->fields as $k => $v) { 00145 if (is_string($v)) $this->fields[$k] = rtrim($v); 00146 } 00147 } 00148 return true; 00149 } 00150 if (!$this->EOF) { 00151 $this->EOF = true; 00152 $this->_currentRow++; 00153 } 00154 return false; 00155 } 00156 00157 /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ 00158 function GetArrayLimit($nrows,$offset=-1) 00159 { 00160 if ($offset <= 0) { 00161 $arr = $this->GetArray($nrows); 00162 return $arr; 00163 } 00164 for ($i=1; $i < $offset; $i++) 00165 if (!@OCIFetch($this->_queryID)) { 00166 $arr = array(); 00167 return $arr; 00168 } 00169 if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { 00170 $arr = array(); 00171 return $arr; 00172 } 00173 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); 00174 $results = array(); 00175 $cnt = 0; 00176 while (!$this->EOF && $nrows != $cnt) { 00177 $results[$cnt++] = $this->fields; 00178 $this->MoveNext(); 00179 } 00180 00181 return $results; 00182 } 00183 00184 // Create associative array 00185 function _updatefields() 00186 { 00187 if (ADODB_ASSOC_CASE == 2) return; // native 00188 00189 $arr = array(); 00190 $lowercase = (ADODB_ASSOC_CASE == 0); 00191 00192 foreach($this->fields as $k => $v) { 00193 if (is_integer($k)) $arr[$k] = $v; 00194 else { 00195 if ($lowercase) 00196 $arr[strtolower($k)] = $v; 00197 else 00198 $arr[strtoupper($k)] = $v; 00199 } 00200 } 00201 $this->fields = $arr; 00202 } 00203 00204 function _fetch() 00205 { 00206 $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); 00207 if ($ret) { 00208 global $ADODB_ANSI_PADDING_OFF; 00209 00210 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); 00211 if (!empty($ADODB_ANSI_PADDING_OFF)) { 00212 foreach($this->fields as $k => $v) { 00213 if (is_string($v)) $this->fields[$k] = rtrim($v); 00214 } 00215 } 00216 } 00217 return $ret; 00218 } 00219 00220 } 00221 00222 00223 ?>