home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / adodb-oci8po.inc.php < prev    next >
Encoding:
PHP Script  |  2004-03-20  |  5.1 KB  |  190 lines

  1. <?php
  2. /*
  3. V4.21 20 Mar 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.     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')";
  27.     
  28.     function ADODB_oci8po()
  29.     {
  30.         $this->ADODB_oci8();
  31.     }
  32.     
  33.     function Param($name)
  34.     {
  35.         return '?';
  36.     }
  37.     
  38.     function Prepare($sql,$cursor=false)
  39.     {
  40.         $sqlarr = explode('?',$sql);
  41.         $sql = $sqlarr[0];
  42.         for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
  43.             $sql .=  ':'.($i-1) . $sqlarr[$i];
  44.         } 
  45.         return ADODB_oci8::Prepare($sql,$cursor);
  46.     }
  47.     
  48.     // emulate handling of parameters ? ?, replacing with :bind0 :bind1
  49.     function _query($sql,$inputarr)
  50.     {
  51.         if (is_array($inputarr)) {
  52.             $i = 0;
  53.             if (is_array($sql)) {
  54.                 foreach($inputarr as $v) {
  55.                     $arr['bind'.$i++] = $v;
  56.                 } 
  57.             } else {
  58.                 $sqlarr = explode('?',$sql);
  59.                 $sql = $sqlarr[0];
  60.                 foreach($inputarr as $k => $v) {
  61.                     $sql .=  ":$k" . $sqlarr[++$i];
  62.                 }
  63.             }
  64.         }
  65.         return ADODB_oci8::_query($sql,$inputarr);
  66.     }
  67. }
  68.  
  69. /*--------------------------------------------------------------------------------------
  70.          Class Name: Recordset
  71. --------------------------------------------------------------------------------------*/
  72.  
  73. class ADORecordset_oci8po extends ADORecordset_oci8 {
  74.  
  75.     var $databaseType = 'oci8po';
  76.     
  77.         function ADORecordset_oci8po($queryID,$mode=false)
  78.         {
  79.             $this->ADORecordset_oci8($queryID,$mode);
  80.         }
  81.  
  82.         function Fields($colname)
  83.         {
  84.             if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname];
  85.             
  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;
  91.                 }
  92.             }
  93.              return $this->fields[$this->bind[strtoupper($colname)]];
  94.         }
  95.         
  96.         // lowercase field names...
  97.          function &_FetchField($fieldOffset = -1)
  98.         {
  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';
  108.                  }
  109.                  return $fld;
  110.         }
  111.  
  112.     // 10% speedup to move MoveNext to child class
  113.     function MoveNext() 
  114.     {
  115.     
  116.         if (!$this->EOF) {        
  117.             $this->_currentRow++;
  118.             if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
  119.             global $ADODB_ANSI_PADDING_OFF;
  120.     
  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);
  125.                     }
  126.                 }
  127.                 return true;
  128.             }
  129.             $this->EOF = true;
  130.         }
  131.         return false;
  132.     }    
  133.     
  134.     /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
  135.     function &GetArrayLimit($nrows,$offset=-1) 
  136.     {
  137.         if ($offset <= 0) return $this->GetArray($nrows);
  138.         for ($i=1; $i < $offset; $i++) 
  139.             if (!@OCIFetch($this->_queryID)) return array();
  140.             
  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();
  148.         }
  149.         
  150.         return $results;
  151.     }
  152.  
  153.     // Create associative array
  154.     function _updatefields()
  155.     {
  156.         if (ADODB_ASSOC_CASE == 2) return; // native
  157.     
  158.         $arr = array();
  159.         $lowercase = (ADODB_ASSOC_CASE == 0);
  160.         
  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;
  168.             }
  169.         }
  170.         $this->fields = $arr;
  171.     }
  172.     
  173.     function _fetch() 
  174.     {
  175.         $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
  176.         if ($ret) {
  177.         global $ADODB_ANSI_PADDING_OFF;
  178.     
  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);
  183.                     }
  184.                 }
  185.         }
  186.         return $ret;
  187.     }
  188.     
  189. }
  190. ?>