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  @version   v5.21.0  2021-02-27
   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 https://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_once(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 ServerInfo()
  37  	 {
  38  	 	 $info = ADODB_odbc::ServerInfo();
  39  	 	 if (!$info['version'] && preg_match('/([0-9.]+)/',$info['description'],$matches)) {
  40  	 	 	 $info['version'] = $matches[1];
  41  	 	 }
  42  	 	 return $info;
  43  	 }
  44  
  45  	function MetaPrimaryKeys($table, $owner = false)
  46  	 {
  47  	 	 $table = $this->Quote(strtoupper($table));
  48  
  49  	 	 return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos");
  50  	 }
  51  
  52  	function MetaIndexes ($table, $primary = FALSE, $owner = false)
  53  	 {
  54  	 	 $table = $this->Quote(strtoupper($table));
  55  
  56  	 	 $sql = "SELECT INDEXNAME,TYPE,COLUMNNAME FROM INDEXCOLUMNS ".
  57  	 	 	 " WHERE TABLENAME=$table".
  58  	 	 	 " ORDER BY INDEXNAME,COLUMNNO";
  59  
  60  	 	 global $ADODB_FETCH_MODE;
  61  	 	 $save = $ADODB_FETCH_MODE;
  62  	 	 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  63  	 	 if ($this->fetchMode !== FALSE) {
  64  	 	 	 $savem = $this->SetFetchMode(FALSE);
  65  	 	 }
  66  
  67  	 	 $rs = $this->Execute($sql);
  68  	 	 if (isset($savem)) {
  69  	 	 	 $this->SetFetchMode($savem);
  70  	 	 }
  71  	 	 $ADODB_FETCH_MODE = $save;
  72  
  73  	 	 if (!is_object($rs)) {
  74  	 	 	 return FALSE;
  75  	 	 }
  76  
  77  	 	 $indexes = array();
  78  	 	 while ($row = $rs->FetchRow()) {
  79  	 	 	 $indexes[$row[0]]['unique'] = $row[1] == 'UNIQUE';
  80  	 	 	 $indexes[$row[0]]['columns'][] = $row[2];
  81  	 	 }
  82  	 	 if ($primary) {
  83  	 	 	 $indexes['SYSPRIMARYKEYINDEX'] = array(
  84  	 	 	 	 	 'unique' => True,	 // by definition
  85  	 	 	 	 	 'columns' => $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos"),
  86  	 	 	 	 );
  87  	 	 }
  88  	 	 return $indexes;
  89  	 }
  90  
  91  	function MetaColumns ($table, $normalize = true)
  92  	 {
  93  	 	 global $ADODB_FETCH_MODE;
  94  	 	 $save = $ADODB_FETCH_MODE;
  95  	 	 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  96  	 	 if ($this->fetchMode !== FALSE) {
  97  	 	 	 $savem = $this->SetFetchMode(FALSE);
  98  	 	 }
  99  	 	 $table = $this->Quote(strtoupper($table));
 100  
 101  	 	 $retarr = array();
 102  	 	 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)
 103  	 	 {
 104  	 	 	 $fld = new ADOFieldObject();
 105  	 	 	 $fld->name = $column[0];
 106  	 	 	 $fld->type = $column[1];
 107  	 	 	 $fld->max_length = $fld->type == 'LONG' ? 2147483647 : $column[2];
 108  	 	 	 $fld->scale = $column[3];
 109  	 	 	 $fld->not_null = $column[4] == 'NO';
 110  	 	 	 $fld->primary_key = $column[5] == 'KEY';
 111  	 	 	 if ($fld->has_default = $column[7]) {
 112  	 	 	 	 if ($fld->primary_key && $column[6] == 'DEFAULT SERIAL (1)') {
 113  	 	 	 	 	 $fld->auto_increment = true;
 114  	 	 	 	 	 $fld->has_default = false;
 115  	 	 	 	 } else {
 116  	 	 	 	 	 $fld->default_value = $column[6];
 117  	 	 	 	 	 switch($fld->type) {
 118  	 	 	 	 	 	 case 'VARCHAR':
 119  	 	 	 	 	 	 case 'CHARACTER':
 120  	 	 	 	 	 	 case 'LONG':
 121  	 	 	 	 	 	 	 $fld->default_value = $column[6];
 122  	 	 	 	 	 	 	 break;
 123  	 	 	 	 	 	 default:
 124  	 	 	 	 	 	 	 $fld->default_value = trim($column[6]);
 125  	 	 	 	 	 	 	 break;
 126  	 	 	 	 	 }
 127  	 	 	 	 }
 128  	 	 	 }
 129  	 	 	 $retarr[$fld->name] = $fld;
 130  	 	 }
 131  	 	 if (isset($savem)) {
 132  	 	 	 $this->SetFetchMode($savem);
 133  	 	 }
 134  	 	 $ADODB_FETCH_MODE = $save;
 135  
 136  	 	 return $retarr;
 137  	 }
 138  
 139  	function MetaColumnNames($table, $numIndexes = false, $useattnum = false)
 140  	 {
 141  	 	 $table = $this->Quote(strtoupper($table));
 142  
 143  	 	 return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table ORDER BY pos");
 144  	 }
 145  
 146  	 // unlike it seems, this depends on the db-session and works in a multiuser environment
 147  	function _insertid($table,$column)
 148  	 {
 149  	 	 return empty($table) ? False : $this->GetOne("SELECT $table.CURRVAL FROM DUAL");
 150  	 }
 151  
 152  	 /*
 153  	 	 SelectLimit implementation problems:
 154  
 155  	 	 The following will return random 10 rows as order by performed after "WHERE rowno<10"
 156  	 	 which is not ideal...
 157  
 158  	 	 	 select * from table where rowno < 10 order by 1
 159  
 160  	 	 This means that we have to use the adoconnection base class SelectLimit when
 161  	 	 there is an "order by".
 162  
 163  	 	 See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html
 164  	  */
 165  
 166  };
 167  
 168  
 169  class ADORecordSet_sapdb extends ADORecordSet_odbc {
 170  
 171  	 var $databaseType = "sapdb";
 172  
 173  }
 174  
 175  } //define