Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  /**
   3   * Data Dictionary for SAP DB.
   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  class ADODB2_sapdb extends ADODB_DataDict {
  26  
  27  	 var $databaseType = 'sapdb';
  28  	 var $seqField = false;
  29  	 var $renameColumn = 'RENAME COLUMN %s.%s TO %s';
  30  
  31   	function ActualType($meta)
  32  	 {
  33  	 	 switch($meta) {
  34  	 	 case 'C': return 'VARCHAR';
  35  	 	 case 'XL':
  36  	 	 case 'X': return 'LONG';
  37  
  38  	 	 case 'C2': return 'VARCHAR UNICODE';
  39  	 	 case 'X2': return 'LONG UNICODE';
  40  
  41  	 	 case 'B': return 'LONG';
  42  
  43  	 	 case 'D': return 'DATE';
  44  	 	 case 'TS':
  45  	 	 case 'T': return 'TIMESTAMP';
  46  
  47  	 	 case 'L': return 'BOOLEAN';
  48  	 	 case 'I': return 'INTEGER';
  49  	 	 case 'I1': return 'FIXED(3)';
  50  	 	 case 'I2': return 'SMALLINT';
  51  	 	 case 'I4': return 'INTEGER';
  52  	 	 case 'I8': return 'FIXED(20)';
  53  
  54  	 	 case 'F': return 'FLOAT(38)';
  55  	 	 case 'N': return 'FIXED';
  56  	 	 default:
  57  	 	 	 return $meta;
  58  	 	 }
  59  	 }
  60  
  61  	function MetaType($t,$len=-1,$fieldobj=false)
  62  	 {
  63  	 	 if (is_object($t)) {
  64  	 	 	 $fieldobj = $t;
  65  	 	 	 $t = $fieldobj->type;
  66  	 	 	 $len = $fieldobj->max_length;
  67  	 	 }
  68  	 	 static $maxdb_type2adodb = array(
  69  	 	 	 'VARCHAR'	 => 'C',
  70  	 	 	 'CHARACTER'	 => 'C',
  71  	 	 	 'LONG'	 	 => 'X',	 	 // no way to differ between 'X' and 'B' :-(
  72  	 	 	 'DATE'	 	 => 'D',
  73  	 	 	 'TIMESTAMP'	 => 'T',
  74  	 	 	 'BOOLEAN'	 => 'L',
  75  	 	 	 'INTEGER'	 => 'I4',
  76  	 	 	 'SMALLINT'	 => 'I2',
  77  	 	 	 'FLOAT'	 	 => 'F',
  78  	 	 	 'FIXED'	 	 => 'N',
  79  	 	 );
  80  	 	 $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : ADODB_DEFAULT_METATYPE;
  81  
  82  	 	 // convert integer-types simulated with fixed back to integer
  83  	 	 if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
  84  	 	 	 $type = $len == 20 ? 'I8' : 'I1';
  85  	 	 }
  86  	 	 if ($fieldobj->auto_increment) $type = 'R';
  87  
  88  	 	 return $type;
  89  	 }
  90  
  91  	 // return string must begin with space
  92  	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
  93  	 {
  94  	 	 $suffix = '';
  95  	 	 if ($funsigned) $suffix .= ' UNSIGNED';
  96  	 	 if ($fnotnull) $suffix .= ' NOT NULL';
  97  	 	 if ($fautoinc) $suffix .= ' DEFAULT SERIAL';
  98  	 	 elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
  99  	 	 if ($fconstraint) $suffix .= ' '.$fconstraint;
 100  	 	 return $suffix;
 101  	 }
 102  
 103  	function AddColumnSQL($tabname, $flds)
 104  	 {
 105  	 	 $tabname = $this->TableName ($tabname);
 106  	 	 $sql = array();
 107  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 108  	 	 return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );
 109  	 }
 110  
 111  	function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
 112  	 {
 113  	 	 $tabname = $this->TableName ($tabname);
 114  	 	 $sql = array();
 115  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 116  	 	 return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );
 117  	 }
 118  
 119  	function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
 120  	 {
 121  	 	 $tabname = $this->TableName ($tabname);
 122  	 	 if (!is_array($flds)) $flds = explode(',',$flds);
 123  	 	 foreach($flds as $k => $v) {
 124  	 	 	 $flds[$k] = $this->NameQuote($v);
 125  	 	 }
 126  	 	 return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );
 127  	 }
 128  }