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  /**
   4    @version   v5.20.16  12-Jan-2020
   5    @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
   6    @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   7    Released under both BSD license and Lesser GPL library license.
   8    Whenever there is any discrepancy between the two licenses,
   9    the BSD license will take precedence.
  10  
  11    Set tabs to 4 for best viewing.
  12  
  13    Modified from datadict-generic.inc.php for sapdb by RalfBecker-AT-outdoor-training.de
  14  */
  15  
  16  // security - hide paths
  17  if (!defined('ADODB_DIR')) die();
  18  
  19  class ADODB2_sapdb extends ADODB_DataDict {
  20  
  21  	 var $databaseType = 'sapdb';
  22  	 var $seqField = false;
  23  	 var $renameColumn = 'RENAME COLUMN %s.%s TO %s';
  24  
  25   	function ActualType($meta)
  26  	 {
  27  	 	 switch($meta) {
  28  	 	 case 'C': return 'VARCHAR';
  29  	 	 case 'XL':
  30  	 	 case 'X': return 'LONG';
  31  
  32  	 	 case 'C2': return 'VARCHAR UNICODE';
  33  	 	 case 'X2': return 'LONG UNICODE';
  34  
  35  	 	 case 'B': return 'LONG';
  36  
  37  	 	 case 'D': return 'DATE';
  38  	 	 case 'TS':
  39  	 	 case 'T': return 'TIMESTAMP';
  40  
  41  	 	 case 'L': return 'BOOLEAN';
  42  	 	 case 'I': return 'INTEGER';
  43  	 	 case 'I1': return 'FIXED(3)';
  44  	 	 case 'I2': return 'SMALLINT';
  45  	 	 case 'I4': return 'INTEGER';
  46  	 	 case 'I8': return 'FIXED(20)';
  47  
  48  	 	 case 'F': return 'FLOAT(38)';
  49  	 	 case 'N': return 'FIXED';
  50  	 	 default:
  51  	 	 	 return $meta;
  52  	 	 }
  53  	 }
  54  
  55  	function MetaType($t,$len=-1,$fieldobj=false)
  56  	 {
  57  	 	 if (is_object($t)) {
  58  	 	 	 $fieldobj = $t;
  59  	 	 	 $t = $fieldobj->type;
  60  	 	 	 $len = $fieldobj->max_length;
  61  	 	 }
  62  	 	 static $maxdb_type2adodb = array(
  63  	 	 	 'VARCHAR'	 => 'C',
  64  	 	 	 'CHARACTER'	 => 'C',
  65  	 	 	 'LONG'	 	 => 'X',	 	 // no way to differ between 'X' and 'B' :-(
  66  	 	 	 'DATE'	 	 => 'D',
  67  	 	 	 'TIMESTAMP'	 => 'T',
  68  	 	 	 'BOOLEAN'	 => 'L',
  69  	 	 	 'INTEGER'	 => 'I4',
  70  	 	 	 'SMALLINT'	 => 'I2',
  71  	 	 	 'FLOAT'	 	 => 'F',
  72  	 	 	 'FIXED'	 	 => 'N',
  73  	 	 );
  74  	 	 $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';
  75  
  76  	 	 // convert integer-types simulated with fixed back to integer
  77  	 	 if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
  78  	 	 	 $type = $len == 20 ? 'I8' : 'I1';
  79  	 	 }
  80  	 	 if ($fieldobj->auto_increment) $type = 'R';
  81  
  82  	 	 return $type;
  83  	 }
  84  
  85  	 // return string must begin with space
  86  	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
  87  	 {
  88  	 	 $suffix = '';
  89  	 	 if ($funsigned) $suffix .= ' UNSIGNED';
  90  	 	 if ($fnotnull) $suffix .= ' NOT NULL';
  91  	 	 if ($fautoinc) $suffix .= ' DEFAULT SERIAL';
  92  	 	 elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
  93  	 	 if ($fconstraint) $suffix .= ' '.$fconstraint;
  94  	 	 return $suffix;
  95  	 }
  96  
  97  	function AddColumnSQL($tabname, $flds)
  98  	 {
  99  	 	 $tabname = $this->TableName ($tabname);
 100  	 	 $sql = array();
 101  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 102  	 	 return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );
 103  	 }
 104  
 105  	function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
 106  	 {
 107  	 	 $tabname = $this->TableName ($tabname);
 108  	 	 $sql = array();
 109  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 110  	 	 return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );
 111  	 }
 112  
 113  	function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
 114  	 {
 115  	 	 $tabname = $this->TableName ($tabname);
 116  	 	 if (!is_array($flds)) $flds = explode(',',$flds);
 117  	 	 foreach($flds as $k => $v) {
 118  	 	 	 $flds[$k] = $this->NameQuote($v);
 119  	 	 }
 120  	 	 return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );
 121  	 }
 122  }