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  /**
   4   * Provided by Ned Andre to support sqlsrv library
   5   */
   6  class ADODB_pdo_sqlsrv extends ADODB_pdo
   7  {
   8  	 var $hasTop = 'top';
   9  	 var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
  10  	 var $sysTimeStamp = 'GetDate()';
  11  	 var $arrayClass = 'ADORecordSet_array_pdo_sqlsrv';
  12  
  13  	function _init(ADODB_pdo $parentDriver)
  14  	 {
  15  	 	 $parentDriver->hasTransactions = true;
  16  	 	 $parentDriver->_bindInputArray = true;
  17  	 	 $parentDriver->hasInsertID = true;
  18  	 	 $parentDriver->fmtTimeStamp = "'Y-m-d H:i:s'";
  19  	 	 $parentDriver->fmtDate = "'Y-m-d'";
  20  	 }
  21  
  22  	function BeginTrans()
  23  	 {
  24  	 	 $returnval = parent::BeginTrans();
  25  	 	 return $returnval;
  26  	 }
  27  
  28  	function MetaColumns($table, $normalize = true)
  29  	 {
  30  	 	 return false;
  31  	 }
  32  
  33  	function MetaTables($ttype = false, $showSchema = false, $mask = false)
  34  	 {
  35  	 	 return false;
  36  	 }
  37  
  38  	function SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0)
  39  	 {
  40  	 	 $ret = ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
  41  	 	 return $ret;
  42  	 }
  43  
  44  	function ServerInfo()
  45  	 {
  46  	 	 return ADOConnection::ServerInfo();
  47  	 }
  48  }
  49  
  50  class ADORecordSet_pdo_sqlsrv extends ADORecordSet_pdo
  51  {
  52  
  53  	 public $databaseType = "pdo_sqlsrv";
  54  
  55  	 /**
  56  	  * returns the field object
  57  	  *
  58  	  * @param  int $fieldOffset Optional field offset
  59  	  *
  60  	  * @return object The ADOFieldObject describing the field
  61  	  */
  62  	public function fetchField($fieldOffset = 0)
  63  	 {
  64  
  65  	 	 // Default behavior allows passing in of -1 offset, which crashes the method
  66  	 	 if ($fieldOffset == -1) {
  67  	 	 	 $fieldOffset++;
  68  	 	 }
  69  
  70  	 	 $o = new ADOFieldObject();
  71  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
  72  
  73  	 	 if (!$arr) {
  74  	 	 	 $o->name = 'bad getColumnMeta()';
  75  	 	 	 $o->max_length = -1;
  76  	 	 	 $o->type = 'VARCHAR';
  77  	 	 	 $o->precision = 0;
  78  	 	 	 return $o;
  79  	 	 }
  80  	 	 $o->name = $arr['name'];
  81  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
  82  	 	 	 // Use the SQL Server driver specific value
  83  	 	 	 $o->type = $arr['sqlsrv:decl_type'];
  84  	 	 } else {
  85  	 	 	 $o->type = adodb_pdo_type($arr['pdo_type']);
  86  	 	 }
  87  	 	 $o->max_length = $arr['len'];
  88  	 	 $o->precision = $arr['precision'];
  89  
  90  	 	 switch (ADODB_ASSOC_CASE) {
  91  	 	 	 case ADODB_ASSOC_CASE_LOWER:
  92  	 	 	 	 $o->name = strtolower($o->name);
  93  	 	 	 	 break;
  94  	 	 	 case ADODB_ASSOC_CASE_UPPER:
  95  	 	 	 	 $o->name = strtoupper($o->name);
  96  	 	 	 	 break;
  97  	 	 }
  98  
  99  	 	 return $o;
 100  	 }
 101  }
 102  
 103  class ADORecordSet_array_pdo_sqlsrv extends ADORecordSet_array_pdo
 104  {
 105  
 106  	 /**
 107  	  * returns the field object
 108  	  *
 109  	  * Note that this is a direct copy of the ADORecordSet_pdo_sqlsrv method
 110  	  *
 111  	  * @param  int $fieldOffset Optional field offset
 112  	  *
 113  	  * @return object The ADOfieldobject describing the field
 114  	  */
 115  	public function fetchField($fieldOffset = 0)
 116  	 {
 117  	 	 // Default behavior allows passing in of -1 offset, which crashes the method
 118  	 	 if ($fieldOffset == -1) {
 119  	 	 	 $fieldOffset++;
 120  	 	 }
 121  
 122  	 	 $o = new ADOFieldObject();
 123  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
 124  
 125  	 	 if (!$arr) {
 126  	 	 	 $o->name = 'bad getColumnMeta()';
 127  	 	 	 $o->max_length = -1;
 128  	 	 	 $o->type = 'VARCHAR';
 129  	 	 	 $o->precision = 0;
 130  	 	 	 return $o;
 131  	 	 }
 132  	 	 $o->name = $arr['name'];
 133  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
 134  	 	 	 // Use the SQL Server driver specific value
 135  	 	 	 $o->type = $arr['sqlsrv:decl_type'];
 136  	 	 } else {
 137  	 	 	 $o->type = adodb_pdo_type($arr['pdo_type']);
 138  	 	 }
 139  	 	 $o->max_length = $arr['len'];
 140  	 	 $o->precision = $arr['precision'];
 141  
 142  	 	 switch (ADODB_ASSOC_CASE) {
 143  	 	 	 case ADODB_ASSOC_CASE_LOWER:
 144  	 	 	 	 $o->name = strtolower($o->name);
 145  	 	 	 	 break;
 146  	 	 	 case ADODB_ASSOC_CASE_UPPER:
 147  	 	 	 	 $o->name = strtoupper($o->name);
 148  	 	 	 	 break;
 149  	 	 }
 150  
 151  	 	 return $o;
 152  	 }
 153  	 
 154  	function SetTransactionMode( $transaction_mode )
 155  	 {
 156  	 	 $this->_transmode  = $transaction_mode;
 157  	 	 if (empty($transaction_mode)) {
 158  	 	 	 $this->_connectionID->query('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
 159  	 	 	 return;
 160  	 	 }
 161  	 	 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
 162  	 	 $this->_connectionID->query("SET TRANSACTION ".$transaction_mode);
 163  	 }
 164  }