Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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    SAPDB data driver. Requires ODBC.
  14  
  15  */
  16  
  17  // security - hide paths
  18  if (!defined('ADODB_DIR')) die();
  19  
  20  if (!defined('_ADODB_ODBC_LAYER')) {
  21  	 include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
  22  }
  23  if (!defined('ADODB_SAPDB')){
  24  define('ADODB_SAPDB',1);
  25  
  26  class ADODB_SAPDB extends ADODB_odbc {
  27  	 var $databaseType = "sapdb";
  28  	 var $concat_operator = '||';
  29  	 var $sysDate = 'DATE';
  30  	 var $sysTimeStamp = 'TIMESTAMP';
  31  	 var $fmtDate = "'Y-m-d'";	 /// used by DBDate() as the default date format used by the database
  32  	 var $fmtTimeStamp = "'Y-m-d H:i:s'"; /// used by DBTimeStamp as the default timestamp fmt.
  33  	 var $hasInsertId = true;
  34  	 var $_bindInputArray = true;
  35  
  36  	function __construct()
  37  	 {
  38  	 	 //if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC;
  39  	 	 parent::__construct();
  40  	 }
  41  
  42  	function ServerInfo()
  43  	 {
  44  	 	 $info = ADODB_odbc::ServerInfo();
  45  	 	 if (!$info['version'] && preg_match('/([0-9.]+)/',$info['description'],$matches)) {
  46  	 	 	 $info['version'] = $matches[1];
  47  	 	 }
  48  	 	 return $info;
  49  	 }
  50  
  51  	function MetaPrimaryKeys($table, $owner = false)
  52  	 {
  53  	 	 $table = $this->Quote(strtoupper($table));
  54  
  55  	 	 return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos");
  56  	 }
  57  
  58   	function MetaIndexes ($table, $primary = FALSE, $owner = false)
  59  	 {
  60  	 	 $table = $this->Quote(strtoupper($table));
  61  
  62  	 	 $sql = "SELECT INDEXNAME,TYPE,COLUMNNAME FROM INDEXCOLUMNS ".
  63  	 	 	 " WHERE TABLENAME=$table".
  64  	 	 	 " ORDER BY INDEXNAME,COLUMNNO";
  65  
  66  	 	 global $ADODB_FETCH_MODE;
  67  	 	 $save = $ADODB_FETCH_MODE;
  68          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  69          if ($this->fetchMode !== FALSE) {
  70          	 $savem = $this->SetFetchMode(FALSE);
  71          }
  72  
  73          $rs = $this->Execute($sql);
  74          if (isset($savem)) {
  75          	 $this->SetFetchMode($savem);
  76          }
  77          $ADODB_FETCH_MODE = $save;
  78  
  79          if (!is_object($rs)) {
  80          	 return FALSE;
  81          }
  82  
  83  	 	 $indexes = array();
  84  	 	 while ($row = $rs->FetchRow()) {
  85              $indexes[$row[0]]['unique'] = $row[1] == 'UNIQUE';
  86              $indexes[$row[0]]['columns'][] = $row[2];
  87      	 }
  88  	 	 if ($primary) {
  89  	 	 	 $indexes['SYSPRIMARYKEYINDEX'] = array(
  90  	 	 	 	 	 'unique' => True,	 // by definition
  91  	 	 	 	 	 'columns' => $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos"),
  92  	 	 	 	 );
  93  	 	 }
  94          return $indexes;
  95  	 }
  96  
  97  	function MetaColumns ($table, $normalize = true)
  98  	 {
  99  	 	 global $ADODB_FETCH_MODE;
 100  	 	 $save = $ADODB_FETCH_MODE;
 101          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 102          if ($this->fetchMode !== FALSE) {
 103          	 $savem = $this->SetFetchMode(FALSE);
 104          }
 105  	 	 $table = $this->Quote(strtoupper($table));
 106  
 107  	 	 $retarr = array();
 108  	 	 foreach($this->GetAll("SELECT COLUMNNAME,DATATYPE,LEN,DEC,NULLABLE,MODE,\"DEFAULT\",CASE WHEN \"DEFAULT\" IS NULL THEN 0 ELSE 1 END AS HAS_DEFAULT FROM COLUMNS WHERE tablename=$table ORDER BY pos") as $column)
 109  	 	 {
 110  	 	 	 $fld = new ADOFieldObject();
 111  	 	 	 $fld->name = $column[0];
 112  	 	 	 $fld->type = $column[1];
 113  	 	 	 $fld->max_length = $fld->type == 'LONG' ? 2147483647 : $column[2];
 114  	 	 	 $fld->scale = $column[3];
 115  	 	 	 $fld->not_null = $column[4] == 'NO';
 116  	 	 	 $fld->primary_key = $column[5] == 'KEY';
 117  	 	 	 if ($fld->has_default = $column[7]) {
 118  	 	 	 	 if ($fld->primary_key && $column[6] == 'DEFAULT SERIAL (1)') {
 119  	 	 	 	 	 $fld->auto_increment = true;
 120  	 	 	 	 	 $fld->has_default = false;
 121  	 	 	 	 } else {
 122  	 	 	 	 	 $fld->default_value = $column[6];
 123  	 	 	 	 	 switch($fld->type) {
 124  	 	 	 	 	 	 case 'VARCHAR':
 125  	 	 	 	 	 	 case 'CHARACTER':
 126  	 	 	 	 	 	 case 'LONG':
 127  	 	 	 	 	 	 	 $fld->default_value = $column[6];
 128  	 	 	 	 	 	 	 break;
 129  	 	 	 	 	 	 default:
 130  	 	 	 	 	 	 	 $fld->default_value = trim($column[6]);
 131  	 	 	 	 	 	 	 break;
 132  	 	 	 	 	 }
 133  	 	 	 	 }
 134  	 	 	 }
 135  	 	 	 $retarr[$fld->name] = $fld;
 136  	 	 }
 137          if (isset($savem)) {
 138          	 $this->SetFetchMode($savem);
 139          }
 140          $ADODB_FETCH_MODE = $save;
 141  
 142  	 	 return $retarr;
 143  	 }
 144  
 145  	function MetaColumnNames($table, $numIndexes = false, $useattnum = false)
 146  	 {
 147  	 	 $table = $this->Quote(strtoupper($table));
 148  
 149  	 	 return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table ORDER BY pos");
 150  	 }
 151  
 152  	 // unlike it seems, this depends on the db-session and works in a multiuser environment
 153  	function _insertid($table,$column)
 154  	 {
 155  	 	 return empty($table) ? False : $this->GetOne("SELECT $table.CURRVAL FROM DUAL");
 156  	 }
 157  
 158  	 /*
 159  	 	 SelectLimit implementation problems:
 160  
 161  	  	 The following will return random 10 rows as order by performed after "WHERE rowno<10"
 162  	  	 which is not ideal...
 163  
 164  	   	 	 select * from table where rowno < 10 order by 1
 165  
 166  	   	 This means that we have to use the adoconnection base class SelectLimit when
 167  	   	 there is an "order by".
 168  
 169  	 	 See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html
 170  	  */
 171  
 172  };
 173  
 174  
 175  class  ADORecordSet_sapdb extends ADORecordSet_odbc {
 176  
 177  	 var $databaseType = "sapdb";
 178  
 179  	function __construct($id,$mode=false)
 180  	 {
 181  	 	 parent::__construct($id,$mode);
 182  	 }
 183  }
 184  
 185  } //define