Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   1  <?php
   2  /*
   3  @version   v5.21.0  2021-02-27
   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 https://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_once(ADODB_DIR."/drivers/adodb-db2.inc.php");
  19  
  20  
  21  if (!defined('ADODB_DB2OCI')){
  22  define('ADODB_DB2OCI',1);
  23  
  24  /**
  25   * Smart remapping of :0, :1 bind vars to ? ?
  26   * Handles colons in comments -- and / * * / and in quoted strings.
  27   * @param string $sql SQL statement
  28   * @param array  $arr parameters
  29   * @return array
  30   */
  31  function _colonparser($sql,$arr)
  32  {
  33  	 $lensql = strlen($sql);
  34  	 $arrsize = sizeof($arr);
  35  	 $state = 'NORM';
  36  	 $at = 1;
  37  	 $ch = $sql[0];
  38  	 $ch2 = @$sql[1];
  39  	 $sql2 = '';
  40  	 $arr2 = array();
  41  	 $nprev = 0;
  42  
  43  
  44  	 while (strlen($ch)) {
  45  
  46  	 	 switch($ch) {
  47  	 	 case '/':
  48  	 	 	 if ($state == 'NORM' && $ch2 == '*') {
  49  	 	 	 	 $state = 'COMMENT';
  50  
  51  	 	 	 	 $at += 1;
  52  	 	 	 	 $ch = $ch2;
  53  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
  54  	 	 	 }
  55  	 	 	 break;
  56  
  57  	 	 case '*':
  58  	 	 	 if ($state == 'COMMENT' && $ch2 == '/') {
  59  	 	 	 	 $state = 'NORM';
  60  
  61  	 	 	 	 $at += 1;
  62  	 	 	 	 $ch = $ch2;
  63  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
  64  	 	 	 }
  65  	 	 	 break;
  66  
  67  	 	 case "\n":
  68  	 	 case "\r":
  69  	 	 	 if ($state == 'COMMENT2') $state = 'NORM';
  70  	 	 	 break;
  71  
  72  	 	 case "'":
  73  	 	 	 do {
  74  	 	 	 	 $at += 1;
  75  	 	 	 	 $ch = $ch2;
  76  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
  77  	 	 	 } while ($ch !== "'");
  78  	 	 	 break;
  79  
  80  	 	 case ':':
  81  	 	 	 if ($state == 'COMMENT' || $state == 'COMMENT2') break;
  82  
  83  	 	 	 //echo "$at=$ch $ch2, ";
  84  	 	 	 if ('0' <= $ch2 && $ch2 <= '9') {
  85  	 	 	 	 $n = '';
  86  	 	 	 	 $nat = $at;
  87  	 	 	 	 do {
  88  	 	 	 	 	 $at += 1;
  89  	 	 	 	 	 $ch = $ch2;
  90  	 	 	 	 	 $n .= $ch;
  91  	 	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
  92  	 	 	 	 } while ('0' <= $ch && $ch <= '9');
  93  	 	 	 	 #echo "$n $arrsize ] ";
  94  	 	 	 	 $n = (integer) $n;
  95  	 	 	 	 if ($n < $arrsize) {
  96  	 	 	 	 	 $sql2 .= substr($sql,$nprev,$nat-$nprev-1).'?';
  97  	 	 	 	 	 $nprev = $at-1;
  98  	 	 	 	 	 $arr2[] = $arr[$n];
  99  	 	 	 	 }
 100  	 	 	 }
 101  	 	 	 break;
 102  
 103  	 	 case '-':
 104  	 	 	 if ($state == 'NORM') {
 105  	 	 	 	 if ($ch2 == '-') $state = 'COMMENT2';
 106  	 	 	 	 $at += 1;
 107  	 	 	 	 $ch = $ch2;
 108  	 	 	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
 109  	 	 	 }
 110  	 	 	 break;
 111  	 	 }
 112  
 113  	 	 $at += 1;
 114  	 	 $ch = $ch2;
 115  	 	 $ch2 = $at < $lensql ? $sql[$at] : '';
 116  	 }
 117  
 118  	 if ($nprev == 0) {
 119  	 	 $sql2 = $sql;
 120  	 } else {
 121  	 	 $sql2 .= substr($sql,$nprev);
 122  	 }
 123  
 124  	 return array($sql2,$arr2);
 125  }
 126  
 127  class ADODB_db2oci extends ADODB_db2 {
 128  	 var $databaseType = "db2oci";
 129  	 var $sysTimeStamp = 'sysdate';
 130  	 var $sysDate = 'trunc(sysdate)';
 131  	 var $_bindInputArray = true;
 132  
 133  	function Param($name,$type='C')
 134  	 {
 135  	 	 return ':'.$name;
 136  	 }
 137  
 138  
 139  	function MetaTables($ttype = false, $schema = false, $mask = false)
 140  	 {
 141  	 global $ADODB_FETCH_MODE;
 142  
 143  	 	 $savem = $ADODB_FETCH_MODE;
 144  	 	 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 145  	 	 $qid = db2_tables($this->_connectionID);
 146  
 147  	 	 $rs = new ADORecordSet_db2($qid);
 148  
 149  	 	 $ADODB_FETCH_MODE = $savem;
 150  	 	 if (!$rs) {
 151  	 	 	 $false = false;
 152  	 	 	 return $false;
 153  	 	 }
 154  
 155  	 	 $arr = $rs->GetArray();
 156  	 	 $rs->Close();
 157  	 	 $arr2 = array();
 158  	 //	 adodb_pr($arr);
 159  	 	 if ($ttype) {
 160  	 	 	 $isview = strncmp($ttype,'V',1) === 0;
 161  	 	 }
 162  	 	 for ($i=0; $i < sizeof($arr); $i++) {
 163  	 	 	 if (!$arr[$i][2]) continue;
 164  	 	 	 $type = $arr[$i][3];
 165  	 	 	 $schemaval = ($schema) ? $arr[$i][1].'.' : '';
 166  	 	 	 $name = $schemaval.$arr[$i][2];
 167  	 	 	 $owner = $arr[$i][1];
 168  	 	 	 if (substr($name,0,8) == 'EXPLAIN_') continue;
 169  	 	 	 if ($ttype) {
 170  	 	 	 	 if ($isview) {
 171  	 	 	 	 	 if (strncmp($type,'V',1) === 0) $arr2[] = $name;
 172  	 	 	 	 } else if (strncmp($type,'T',1) === 0 && strncmp($owner,'SYS',3) !== 0) $arr2[] = $name;
 173  	 	 	 } else if (strncmp($type,'T',1) === 0 && strncmp($owner,'SYS',3) !== 0) $arr2[] = $name;
 174  	 	 }
 175  	 	 return $arr2;
 176  	 }
 177  
 178  	function _Execute($sql, $inputarr=false	 )
 179  	 {
 180  	 	 if ($inputarr) list($sql,$inputarr) = _colonparser($sql, $inputarr);
 181  	 	 return parent::_Execute($sql, $inputarr);
 182  	 }
 183  };
 184  
 185  
 186  class  ADORecordSet_db2oci extends ADORecordSet_db2 {
 187  
 188  	 var $databaseType = "db2oci";
 189  
 190  }
 191  
 192  } //define