Documentation TYPO3 par Ameos

adodb-oci8po.inc.php

00001 <?php
00002 /*
00003 V4.80 8 Mar 2006  (c) 2000-2006 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         // emulate handling of parameters ? ?, replacing with :bind0 :bind1
00053         function _query($sql,$inputarr)
00054         {
00055                 if (is_array($inputarr)) {
00056                         $i = 0;
00057                         if (is_array($sql)) {
00058                                 foreach($inputarr as $v) {
00059                                         $arr['bind'.$i++] = $v;
00060                                 } 
00061                         } else {
00062                                 $sqlarr = explode('?',$sql);
00063                                 $sql = $sqlarr[0];
00064                                 foreach($inputarr as $k => $v) {
00065                                         $sql .=  ":$k" . $sqlarr[++$i];
00066                                 }
00067                         }
00068                 }
00069                 return ADODB_oci8::_query($sql,$inputarr);
00070         }
00071 }
00072 
00073 /*--------------------------------------------------------------------------------------
00074                  Class Name: Recordset
00075 --------------------------------------------------------------------------------------*/
00076 
00077 class ADORecordset_oci8po extends ADORecordset_oci8 {
00078 
00079         var $databaseType = 'oci8po';
00080         
00081         function ADORecordset_oci8po($queryID,$mode=false)
00082         {
00083                 $this->ADORecordset_oci8($queryID,$mode);
00084         }
00085 
00086         function Fields($colname)
00087         {
00088                 if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
00089                 
00090                 if (!$this->bind) {
00091                         $this->bind = array();
00092                         for ($i=0; $i < $this->_numOfFields; $i++) {
00093                                 $o = $this->FetchField($i);
00094                                 $this->bind[strtoupper($o->name)] = $i;
00095                         }
00096                 }
00097                  return $this->fields[$this->bind[strtoupper($colname)]];
00098         }
00099         
00100         // lowercase field names...
00101         function &_FetchField($fieldOffset = -1)
00102         {
00103                  $fld = new ADOFieldObject;
00104                  $fieldOffset += 1;
00105                  $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset));
00106                  $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
00107                  $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
00108                  if ($fld->type == 'NUMBER') {
00109                         //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
00110                         $sc = OCIColumnScale($this->_queryID, $fieldOffset);
00111                         if ($sc == 0) $fld->type = 'INT';
00112                  }
00113                  return $fld;
00114         }
00115         /*
00116         function MoveNext()
00117         {
00118                 if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
00119                         $this->_currentRow += 1;
00120                         return true;
00121                 }
00122                 if (!$this->EOF) {
00123                         $this->_currentRow += 1;
00124                         $this->EOF = true;
00125                 }
00126                 return false;
00127         }*/
00128 
00129         // 10% speedup to move MoveNext to child class
00130         function MoveNext() 
00131         {
00132                 if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
00133                 global $ADODB_ANSI_PADDING_OFF;
00134                         $this->_currentRow++;
00135                         
00136                         if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
00137                         if (!empty($ADODB_ANSI_PADDING_OFF)) {
00138                                 foreach($this->fields as $k => $v) {
00139                                         if (is_string($v)) $this->fields[$k] = rtrim($v);
00140                                 }
00141                         }
00142                         return true;
00143                 }
00144                 if (!$this->EOF) {
00145                         $this->EOF = true;
00146                         $this->_currentRow++;
00147                 }
00148                 return false;
00149         }       
00150         
00151         /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
00152         function &GetArrayLimit($nrows,$offset=-1) 
00153         {
00154                 if ($offset <= 0) {
00155                         $arr = $this->GetArray($nrows);
00156                         return $arr;
00157                 }
00158                 for ($i=1; $i < $offset; $i++) 
00159                         if (!@OCIFetch($this->_queryID)) {
00160                                 $arr = array();
00161                                 return $arr;
00162                         }
00163                 if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
00164                         $arr = array();
00165                         return $arr;
00166                 }
00167                 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
00168                 $results = array();
00169                 $cnt = 0;
00170                 while (!$this->EOF && $nrows != $cnt) {
00171                         $results[$cnt++] = $this->fields;
00172                         $this->MoveNext();
00173                 }
00174                 
00175                 return $results;
00176         }
00177 
00178         // Create associative array
00179         function _updatefields()
00180         {
00181                 if (ADODB_ASSOC_CASE == 2) return; // native
00182         
00183                 $arr = array();
00184                 $lowercase = (ADODB_ASSOC_CASE == 0);
00185                 
00186                 foreach($this->fields as $k => $v) {
00187                         if (is_integer($k)) $arr[$k] = $v;
00188                         else {
00189                                 if ($lowercase)
00190                                         $arr[strtolower($k)] = $v;
00191                                 else
00192                                         $arr[strtoupper($k)] = $v;
00193                         }
00194                 }
00195                 $this->fields = $arr;
00196         }
00197         
00198         function _fetch() 
00199         {
00200                 $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
00201                 if ($ret) {
00202                 global $ADODB_ANSI_PADDING_OFF;
00203         
00204                                 if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
00205                                 if (!empty($ADODB_ANSI_PADDING_OFF)) {
00206                                         foreach($this->fields as $k => $v) {
00207                                                 if (is_string($v)) $this->fields[$k] = rtrim($v);
00208                                         }
00209                                 }
00210                 }
00211                 return $ret;
00212         }
00213         
00214 }
00215 
00216 
00217 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6