Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  /**
   3   * PDO Oracle (oci) driver
   4   *
   5   * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
   6   *
   7   * @package ADOdb
   8   * @link https://adodb.org Project's web site and documentation
   9   * @link https://github.com/ADOdb/ADOdb Source code and issue tracker
  10   *
  11   * The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
  12   * and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
  13   * any later version. This means you can use it in proprietary products.
  14   * See the LICENSE.md file distributed with this source code for details.
  15   * @license BSD-3-Clause
  16   * @license LGPL-2.1-or-later
  17   *
  18   * @copyright 2000-2013 John Lim
  19   * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
  20   */
  21  
  22  class ADODB_pdo_oci extends ADODB_pdo_base {
  23  
  24  	 var $concat_operator='||';
  25  	 var $sysDate = "TRUNC(SYSDATE)";
  26  	 var $sysTimeStamp = 'SYSDATE';
  27  	 var $NLS_DATE_FORMAT = 'YYYY-MM-DD';  // To include time, use 'RRRR-MM-DD HH24:MI:SS'
  28  	 var $random = "abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)";
  29  	 var $metaTablesSQL = "select table_name,table_type from cat where table_type in ('TABLE','VIEW')";
  30  	 var $metaColumnsSQL = "select cname,coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno";
  31  
  32   	 var $_initdate = true;
  33  	 var $_hasdual = true;
  34  
  35  	function _init($parentDriver)
  36  	 {
  37  	 	 $parentDriver->_bindInputArray = true;
  38  	 	 $parentDriver->_nestedSQL = true;
  39  	 	 if ($this->_initdate) {
  40  	 	 	 $parentDriver->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'");
  41  	 	 }
  42  	 }
  43  
  44  	function MetaTables($ttype=false,$showSchema=false,$mask=false)
  45  	 {
  46  	 	 if ($mask) {
  47  	 	 	 $save = $this->metaTablesSQL;
  48  	 	 	 $mask = $this->qstr(strtoupper($mask));
  49  	 	 	 $this->metaTablesSQL .= " AND table_name like $mask";
  50  	 	 }
  51  	 	 $ret = ADOConnection::MetaTables($ttype,$showSchema);
  52  
  53  	 	 if ($mask) {
  54  	 	 	 $this->metaTablesSQL = $save;
  55  	 	 }
  56  	 	 return $ret;
  57  	 }
  58  
  59  	function MetaColumns($table,$normalize=true)
  60  	 {
  61  	 global $ADODB_FETCH_MODE;
  62  
  63  	 	 $false = false;
  64  	 	 $save = $ADODB_FETCH_MODE;
  65  	 	 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  66  	 	 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
  67  
  68  	 	 $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
  69  
  70  	 	 if (isset($savem)) $this->SetFetchMode($savem);
  71  	 	 $ADODB_FETCH_MODE = $save;
  72  	 	 if (!$rs) {
  73  	 	 	 return $false;
  74  	 	 }
  75  	 	 $retarr = array();
  76  	 	 while (!$rs->EOF) { //print_r($rs->fields);
  77  	 	 	 $fld = new ADOFieldObject();
  78  	    	 	 $fld->name = $rs->fields[0];
  79  	    	 	 $fld->type = $rs->fields[1];
  80  	    	 	 $fld->max_length = $rs->fields[2];
  81  	 	 	 $fld->scale = $rs->fields[3];
  82  	 	 	 if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) {
  83  	 	 	 	 $fld->type ='INT';
  84  	      	 	 $fld->max_length = $rs->fields[4];
  85  	     	 }
  86  	 	    	 $fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0);
  87  	 	 	 $fld->binary = (strpos($fld->type,'BLOB') !== false);
  88  	 	 	 $fld->default_value = $rs->fields[6];
  89  
  90  	 	 	 if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
  91  	 	 	 else $retarr[strtoupper($fld->name)] = $fld;
  92  	 	 	 $rs->MoveNext();
  93  	 	 }
  94  	 	 $rs->Close();
  95  	 	 if (empty($retarr))
  96  	 	 	 return  $false;
  97  	 	 else
  98  	 	 	 return $retarr;
  99  	 }
 100  
 101      /**
 102       * @param bool $auto_commit
 103       * @return void
 104       */
 105      function SetAutoCommit($auto_commit)
 106      {
 107          $this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT, $auto_commit);
 108      }
 109  }