Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

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