Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

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