Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   1  <?php
   2  /*
   3  @version   v5.20.16  12-Jan-2020
   4  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
   5  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   6    Released under both BSD license and Lesser GPL library license.
   7    Whenever there is any discrepancy between the two licenses,
   8    the BSD license will take precedence.
   9  Set tabs to 4 for best viewing.
  10  
  11    Latest version is available at http://adodb.org/
  12  
  13    Microsoft Visual FoxPro data driver. Requires ODBC. Works only on MS Windows.
  14  */
  15  
  16  // security - hide paths
  17  if (!defined('ADODB_DIR')) die();
  18  include(ADODB_DIR."/drivers/adodb-db2.inc.php");
  19  
  20  
  21  if (!defined('ADODB_DB2OCI')){
  22  define('ADODB_DB2OCI',1);
  23  
  24  /*
  25  // regex code for smart remapping of :0, :1 bind vars to ? ?
  26  function _colontrack($p)
  27  {
  28  global $_COLONARR,$_COLONSZ;
  29  	 $v = (integer) substr($p,1);
  30  	 if ($v > $_COLONSZ) return $p;
  31  	 $_COLONARR[] = $v;
  32  	 return '?';
  33  }
  34  
  35  // smart remapping of :0, :1 bind vars to ? ?
  36  function _colonscope($sql,$arr)
  37  {
  38  global $_COLONARR,$_COLONSZ;
  39  
  40  	 $_COLONARR = array();
  41  	 $_COLONSZ = sizeof($arr);
  42  
  43  	 $sql2 = preg_replace("/(:[0-9]+)/e","_colontrack('\\1')",$sql);
  44  
  45  	 if (empty($_COLONARR)) return array($sql,$arr);
  46  
  47  	 foreach($_COLONARR as $k => $v) {
  48  	 	 $arr2[] = $arr[$v];
  49  	 }
  50  
  51  	 return array($sql2,$arr2);
  52  }
  53  */
  54  
  55  /*
  56  	 Smart remapping of :0, :1 bind vars to ? ?
  57  
  58  	 Handles colons in comments -- and / * * / and in quoted strings.
  59  */
  60  
  61  function _colonparser($sql,$arr)
  62  {
  63  	 $lensql = strlen($sql);
  64  	 $arrsize = sizeof($arr);
  65  	 $state = 'NORM';
  66  	 $at = 1;
  67  	 $ch = $sql[0];
  68  	 $ch2 = @$sql[1];
  69  	 $sql2 = '';
  70  	 $arr2 = array();
  71  	 $nprev = 0;
  72  
  73  
  74  	 while (strlen($ch)) {
  75  
  76  	 	 switch($ch) {
  77  	 	 case '/':
  78  	 	 	 if ($state == 'NORM' && $ch2 == '*') {
  79  	 	 	 	 $state = 'COMMENT';
  80  
  81  	 	 	 	 $at += 1;
  82  	 	 	 	 $ch = $ch2;
  83  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
  84  	 	 	 }
  85  	 	 	 break;
  86  
  87  	 	 case '*':
  88  	 	 	 if ($state == 'COMMENT' && $ch2 == '/') {
  89  	 	 	 	 $state = 'NORM';
  90  
  91  	 	 	 	 $at += 1;
  92  	 	 	 	 $ch = $ch2;
  93  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
  94  	 	 	 }
  95  	 	 	 break;
  96  
  97  	 	 case "\n":
  98  	 	 case "\r":
  99  	 	 	 if ($state == 'COMMENT2') $state = 'NORM';
 100  	 	 	 break;
 101  
 102  	 	 case "'":
 103  	 	 	 do {
 104  	 	 	 	 $at += 1;
 105  	 	 	 	 $ch = $ch2;
 106  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
 107  	 	 	 } while ($ch !== "'");
 108  	 	 	 break;
 109  
 110  	 	 case ':':
 111  	 	 	 if ($state == 'COMMENT' || $state == 'COMMENT2') break;
 112  
 113  	 	 	 //echo "$at=$ch $ch2, ";
 114  	 	 	 if ('0' <= $ch2 && $ch2 <= '9') {
 115  	 	 	 	 $n = '';
 116  	 	 	 	 $nat = $at;
 117  	 	 	 	 do {
 118  	 	 	 	 	 $at += 1;
 119  	 	 	 	 	 $ch = $ch2;
 120  	 	 	 	 	 $n .= $ch;
 121  	 	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
 122  	 	 	 	 } while ('0' <= $ch && $ch <= '9');
 123  	 	 	 	 #echo "$n $arrsize ] ";
 124  	 	 	 	 $n = (integer) $n;
 125  	 	 	 	 if ($n < $arrsize) {
 126  	 	 	 	 	 $sql2 .= substr($sql,$nprev,$nat-$nprev-1).'?';
 127  	 	 	 	 	 $nprev = $at-1;
 128  	 	 	 	 	 $arr2[] = $arr[$n];
 129  	 	 	 	 }
 130  	 	 	 }
 131  	 	 	 break;
 132  
 133  	 	 case '-':
 134  	 	 	 if ($state == 'NORM') {
 135  	 	 	 	 if ($ch2 == '-') $state = 'COMMENT2';
 136  	 	 	 	 $at += 1;
 137  	 	 	 	 $ch = $ch2;
 138  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
 139  	 	 	 }
 140  	 	 	 break;
 141  	 	 }
 142  
 143  	 	 $at += 1;
 144  	 	 $ch = $ch2;
 145  	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
 146  	 }
 147  
 148  	 if ($nprev == 0) {
 149  	 	 $sql2 = $sql;
 150  	 } else {
 151  	 	 $sql2 .= substr($sql,$nprev);
 152  	 }
 153  
 154  	 return array($sql2,$arr2);
 155  }
 156  
 157  class ADODB_db2oci extends ADODB_db2 {
 158  	 var $databaseType = "db2oci";
 159  	 var $sysTimeStamp = 'sysdate';
 160  	 var $sysDate = 'trunc(sysdate)';
 161  	 var $_bindInputArray = true;
 162  
 163  	function Param($name,$type='C')
 164  	 {
 165  	 	 return ':'.$name;
 166  	 }
 167  
 168  
 169  	function MetaTables($ttype = false, $schema = false, $mask = false)
 170  	 {
 171  	 global $ADODB_FETCH_MODE;
 172  
 173  	 	 $savem = $ADODB_FETCH_MODE;
 174  	 	 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 175  	 	 $qid = db2_tables($this->_connectionID);
 176  
 177  	 	 $rs = new ADORecordSet_db2($qid);
 178  
 179  	 	 $ADODB_FETCH_MODE = $savem;
 180  	 	 if (!$rs) {
 181  	 	 	 $false = false;
 182  	 	 	 return $false;
 183  	 	 }
 184  
 185  	 	 $arr = $rs->GetArray();
 186  	 	 $rs->Close();
 187  	 	 $arr2 = array();
 188  	 //	 adodb_pr($arr);
 189  	 	 if ($ttype) {
 190  	 	 	 $isview = strncmp($ttype,'V',1) === 0;
 191  	 	 }
 192  	 	 for ($i=0; $i < sizeof($arr); $i++) {
 193  	 	 	 if (!$arr[$i][2]) continue;
 194  	 	 	 $type = $arr[$i][3];
 195  	 	 	 $schemaval = ($schema) ? $arr[$i][1].'.' : '';
 196  	 	 	 $name = $schemaval.$arr[$i][2];
 197  	 	 	 $owner = $arr[$i][1];
 198  	 	 	 if (substr($name,0,8) == 'EXPLAIN_') continue;
 199  	 	 	 if ($ttype) {
 200  	 	 	 	 if ($isview) {
 201  	 	 	 	 	 if (strncmp($type,'V',1) === 0) $arr2[] = $name;
 202  	 	 	 	 } else if (strncmp($type,'T',1) === 0 && strncmp($owner,'SYS',3) !== 0) $arr2[] = $name;
 203  	 	 	 } else if (strncmp($type,'T',1) === 0 && strncmp($owner,'SYS',3) !== 0) $arr2[] = $name;
 204  	 	 }
 205  	 	 return $arr2;
 206  	 }
 207  
 208  	function _Execute($sql, $inputarr=false	 )
 209  	 {
 210  	 	 if ($inputarr) list($sql,$inputarr) = _colonparser($sql, $inputarr);
 211  	 	 return parent::_Execute($sql, $inputarr);
 212  	 }
 213  };
 214  
 215  
 216  class  ADORecordSet_db2oci extends ADORecordSet_db2 {
 217  
 218  	 var $databaseType = "db2oci";
 219  
 220  	function __construct($id,$mode=false)
 221  	 {
 222  	 	 return parent::__construct($id,$mode);
 223  	 }
 224  }
 225  
 226  } //define