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 SQL Server ADO data driver. Requires ADO and MSSQL client.
  14    Works only on MS Windows.
  15  
  16    Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used.
  17    Please check http://bugs.php.net/ for more info.
  18  */
  19  
  20  // security - hide paths
  21  if (!defined('ADODB_DIR')) die();
  22  
  23  if (!defined('_ADODB_ADO_LAYER')) {
  24  	 if (PHP_VERSION >= 5) include(ADODB_DIR."/drivers/adodb-ado5.inc.php");
  25  	 else include(ADODB_DIR."/drivers/adodb-ado.inc.php");
  26  }
  27  
  28  
  29  class  ADODB_ado_mssql extends ADODB_ado {
  30  	 var $databaseType = 'ado_mssql';
  31  	 var $hasTop = 'top';
  32  	 var $hasInsertID = true;
  33  	 var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
  34  	 var $sysTimeStamp = 'GetDate()';
  35  	 var $leftOuter = '*=';
  36  	 var $rightOuter = '=*';
  37  	 var $ansiOuter = true; // for mssql7 or later
  38  	 var $substr = "substring";
  39  	 var $length = 'len';
  40  	 var $_dropSeqSQL = "drop table %s";
  41  
  42  	 //var $_inTransaction = 1; // always open recordsets, so no transaction problems.
  43  
  44  	function _insertid()
  45  	 {
  46  	         return $this->GetOne('select SCOPE_IDENTITY()');
  47  	 }
  48  
  49  	function _affectedrows()
  50  	 {
  51  	         return $this->GetOne('select @@rowcount');
  52  	 }
  53  
  54  	function SetTransactionMode( $transaction_mode )
  55  	 {
  56  	 	 $this->_transmode  = $transaction_mode;
  57  	 	 if (empty($transaction_mode)) {
  58  	 	 	 $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
  59  	 	 	 return;
  60  	 	 }
  61  	 	 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
  62  	 	 $this->Execute("SET TRANSACTION ".$transaction_mode);
  63  	 }
  64  
  65  	function qstr($s,$magic_quotes=false)
  66  	 {
  67  	 	 $s = ADOConnection::qstr($s, $magic_quotes);
  68  	 	 return str_replace("\0", "\\\\000", $s);
  69  	 }
  70  
  71  	function MetaColumns($table, $normalize=true)
  72  	 {
  73          $table = strtoupper($table);
  74          $arr= array();
  75          $dbc = $this->_connectionID;
  76  
  77          $osoptions = array();
  78          $osoptions[0] = null;
  79          $osoptions[1] = null;
  80          $osoptions[2] = $table;
  81          $osoptions[3] = null;
  82  
  83          $adors=@$dbc->OpenSchema(4, $osoptions);//tables
  84  
  85          if ($adors){
  86                  while (!$adors->EOF){
  87                          $fld = new ADOFieldObject();
  88                          $c = $adors->Fields(3);
  89                          $fld->name = $c->Value;
  90                          $fld->type = 'CHAR'; // cannot discover type in ADO!
  91                          $fld->max_length = -1;
  92                          $arr[strtoupper($fld->name)]=$fld;
  93  
  94                          $adors->MoveNext();
  95                  }
  96                  $adors->Close();
  97          }
  98          $false = false;
  99  	 	 return empty($arr) ? $false : $arr;
 100  	 }
 101  
 102  	function CreateSequence($seq='adodbseq',$start=1)
 103  	 {
 104  
 105  	 	 $this->Execute('BEGIN TRANSACTION adodbseq');
 106  	 	 $start -= 1;
 107  	 	 $this->Execute("create table $seq (id float(53))");
 108  	 	 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
 109  	 	 if (!$ok) {
 110  	 	 	 	 $this->Execute('ROLLBACK TRANSACTION adodbseq');
 111  	 	 	 	 return false;
 112  	 	 }
 113  	 	 $this->Execute('COMMIT TRANSACTION adodbseq');
 114  	 	 return true;
 115  	 }
 116  
 117  	function GenID($seq='adodbseq',$start=1)
 118  	 {
 119  	 	 //$this->debug=1;
 120  	 	 $this->Execute('BEGIN TRANSACTION adodbseq');
 121  	 	 $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
 122  	 	 if (!$ok) {
 123  	 	 	 $this->Execute("create table $seq (id float(53))");
 124  	 	 	 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
 125  	 	 	 if (!$ok) {
 126  	 	 	 	 $this->Execute('ROLLBACK TRANSACTION adodbseq');
 127  	 	 	 	 return false;
 128  	 	 	 }
 129  	 	 	 $this->Execute('COMMIT TRANSACTION adodbseq');
 130  	 	 	 return $start;
 131  	 	 }
 132  	 	 $num = $this->GetOne("select id from $seq");
 133  	 	 $this->Execute('COMMIT TRANSACTION adodbseq');
 134  	 	 return $num;
 135  
 136  	 	 // in old implementation, pre 1.90, we returned GUID...
 137  	 	 //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'");
 138  	 }
 139  
 140  	 } // end class
 141  
 142  	 class  ADORecordSet_ado_mssql extends ADORecordSet_ado {
 143  
 144  	 var $databaseType = 'ado_mssql';
 145  
 146  	function __construct($id,$mode=false)
 147  	 {
 148  	         return parent::__construct($id,$mode);
 149  	 }
 150  }