[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/adodb/drivers/ -> adodb-oci8po.inc.php (source)

   1  <?php
   2  /*
   3  V5.11 5 May 2010   (c) 2000-2010 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=false)
  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 = OCIcolumnname($this->_queryID, $fieldOffset);
 106           if (ADODB_ASSOC_CASE == 0) $fld->name = strtolower($fld->name);
 107           $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
 108           $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
 109           if ($fld->type == 'NUMBER') {
 110               //$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
 111              $sc = OCIColumnScale($this->_queryID, $fieldOffset);
 112              if ($sc == 0) $fld->type = 'INT';
 113           }
 114           return $fld;
 115      }
 116      /*
 117      function MoveNext()
 118      {
 119          if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
 120              $this->_currentRow += 1;
 121              return true;
 122          }
 123          if (!$this->EOF) {
 124              $this->_currentRow += 1;
 125              $this->EOF = true;
 126          }
 127          return false;
 128      }*/
 129  
 130      // 10% speedup to move MoveNext to child class
 131  	function MoveNext() 
 132      {
 133          if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
 134          global $ADODB_ANSI_PADDING_OFF;
 135              $this->_currentRow++;
 136              
 137              if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
 138              if (!empty($ADODB_ANSI_PADDING_OFF)) {
 139                  foreach($this->fields as $k => $v) {
 140                      if (is_string($v)) $this->fields[$k] = rtrim($v);
 141                  }
 142              }
 143              return true;
 144          }
 145          if (!$this->EOF) {
 146              $this->EOF = true;
 147              $this->_currentRow++;
 148          }
 149          return false;
 150      }    
 151      
 152      /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
 153  	function GetArrayLimit($nrows,$offset=-1) 
 154      {
 155          if ($offset <= 0) {
 156              $arr = $this->GetArray($nrows);
 157              return $arr;
 158          }
 159          for ($i=1; $i < $offset; $i++) 
 160              if (!@OCIFetch($this->_queryID)) {
 161                  $arr = array();
 162                  return $arr;
 163              }
 164          if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
 165              $arr = array();
 166              return $arr;
 167          }
 168          if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
 169          $results = array();
 170          $cnt = 0;
 171          while (!$this->EOF && $nrows != $cnt) {
 172              $results[$cnt++] = $this->fields;
 173              $this->MoveNext();
 174          }
 175          
 176          return $results;
 177      }
 178  
 179      // Create associative array
 180  	function _updatefields()
 181      {
 182          if (ADODB_ASSOC_CASE == 2) return; // native
 183      
 184          $arr = array();
 185          $lowercase = (ADODB_ASSOC_CASE == 0);
 186          
 187          foreach($this->fields as $k => $v) {
 188              if (is_integer($k)) $arr[$k] = $v;
 189              else {
 190                  if ($lowercase)
 191                      $arr[strtolower($k)] = $v;
 192                  else
 193                      $arr[strtoupper($k)] = $v;
 194              }
 195          }
 196          $this->fields = $arr;
 197      }
 198      
 199  	function _fetch() 
 200      {
 201          $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
 202          if ($ret) {
 203          global $ADODB_ANSI_PADDING_OFF;
 204      
 205                  if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
 206                  if (!empty($ADODB_ANSI_PADDING_OFF)) {
 207                      foreach($this->fields as $k => $v) {
 208                          if (is_string($v)) $this->fields[$k] = rtrim($v);
 209                      }
 210                  }
 211          }
 212          return $ret;
 213      }
 214      
 215  }
 216  
 217  
 218  ?>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7