Search moodle.org's
Developer Documentation

See Release Notes

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

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [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  	 	 return ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
  63  	 }
  64  
  65  	function ServerInfo()
  66  	 {
  67  	 	 return ADOConnection::ServerInfo();
  68  	 }
  69  }
  70  
  71  class ADORecordSet_pdo_sqlsrv extends ADORecordSet_pdo
  72  {
  73  
  74  	 public $databaseType = "pdo_sqlsrv";
  75  
  76  	 /**
  77  	  * returns the field object
  78  	  *
  79  	  * @param  int $fieldOffset Optional field offset
  80  	  *
  81  	  * @return object The ADOFieldObject describing the field
  82  	  */
  83  	public function fetchField($fieldOffset = 0)
  84  	 {
  85  
  86  	 	 // Default behavior allows passing in of -1 offset, which crashes the method
  87  	 	 if ($fieldOffset == -1) {
  88  	 	 	 $fieldOffset++;
  89  	 	 }
  90  
  91  	 	 $o = new ADOFieldObject();
  92  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
  93  
  94  	 	 if (!$arr) {
  95  	 	 	 $o->name = 'bad getColumnMeta()';
  96  	 	 	 $o->max_length = -1;
  97  	 	 	 $o->type = 'VARCHAR';
  98  	 	 	 $o->precision = 0;
  99  	 	 	 return $o;
 100  	 	 }
 101  	 	 $o->name = $arr['name'];
 102  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
 103  	 	 	 // Use the SQL Server driver specific value
 104  	 	 	 $o->type = $arr['sqlsrv:decl_type'];
 105  	 	 } else {
 106  	 	 	 $o->type = adodb_pdo_type($arr['pdo_type']);
 107  	 	 }
 108  	 	 $o->max_length = $arr['len'];
 109  	 	 $o->precision = $arr['precision'];
 110  
 111  	 	 switch (ADODB_ASSOC_CASE) {
 112  	 	 	 case ADODB_ASSOC_CASE_LOWER:
 113  	 	 	 	 $o->name = strtolower($o->name);
 114  	 	 	 	 break;
 115  	 	 	 case ADODB_ASSOC_CASE_UPPER:
 116  	 	 	 	 $o->name = strtoupper($o->name);
 117  	 	 	 	 break;
 118  	 	 }
 119  
 120  	 	 return $o;
 121  	 }
 122  }
 123  
 124  class ADORecordSet_array_pdo_sqlsrv extends ADORecordSet_array_pdo
 125  {
 126  
 127  	 /**
 128  	  * returns the field object
 129  	  *
 130  	  * Note that this is a direct copy of the ADORecordSet_pdo_sqlsrv method
 131  	  *
 132  	  * @param  int $fieldOffset Optional field offset
 133  	  *
 134  	  * @return object The ADOfieldobject describing the field
 135  	  */
 136  	public function fetchField($fieldOffset = 0)
 137  	 {
 138  	 	 // Default behavior allows passing in of -1 offset, which crashes the method
 139  	 	 if ($fieldOffset == -1) {
 140  	 	 	 $fieldOffset++;
 141  	 	 }
 142  
 143  	 	 $o = new ADOFieldObject();
 144  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
 145  
 146  	 	 if (!$arr) {
 147  	 	 	 $o->name = 'bad getColumnMeta()';
 148  	 	 	 $o->max_length = -1;
 149  	 	 	 $o->type = 'VARCHAR';
 150  	 	 	 $o->precision = 0;
 151  	 	 	 return $o;
 152  	 	 }
 153  	 	 $o->name = $arr['name'];
 154  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
 155  	 	 	 // Use the SQL Server driver specific value
 156  	 	 	 $o->type = $arr['sqlsrv:decl_type'];
 157  	 	 } else {
 158  	 	 	 $o->type = adodb_pdo_type($arr['pdo_type']);
 159  	 	 }
 160  	 	 $o->max_length = $arr['len'];
 161  	 	 $o->precision = $arr['precision'];
 162  
 163  	 	 switch (ADODB_ASSOC_CASE) {
 164  	 	 	 case ADODB_ASSOC_CASE_LOWER:
 165  	 	 	 	 $o->name = strtolower($o->name);
 166  	 	 	 	 break;
 167  	 	 	 case ADODB_ASSOC_CASE_UPPER:
 168  	 	 	 	 $o->name = strtoupper($o->name);
 169  	 	 	 	 break;
 170  	 	 }
 171  
 172  	 	 return $o;
 173  	 }
 174  
 175  }