Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

   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  	 	 $meta = strtoupper($meta);
  34  	 	 
  35  	 	 /*
  36  	 	 * Add support for custom meta types. We do this
  37  	 	 * first, that allows us to override existing types
  38  	 	 */
  39  	 	 if (isset($this->connection->customMetaTypes[$meta]))
  40  	 	 	 return $this->connection->customMetaTypes[$meta]['actual'];
  41  	 	 
  42  	 	 switch($meta) {
  43  	 	 case 'C': return 'VARCHAR';
  44  	 	 case 'XL':
  45  	 	 case 'X': return 'LONG';
  46  
  47  	 	 case 'C2': return 'VARCHAR UNICODE';
  48  	 	 case 'X2': return 'LONG UNICODE';
  49  
  50  	 	 case 'B': return 'LONG';
  51  
  52  	 	 case 'D': return 'DATE';
  53  	 	 case 'TS':
  54  	 	 case 'T': return 'TIMESTAMP';
  55  
  56  	 	 case 'L': return 'BOOLEAN';
  57  	 	 case 'I': return 'INTEGER';
  58  	 	 case 'I1': return 'FIXED(3)';
  59  	 	 case 'I2': return 'SMALLINT';
  60  	 	 case 'I4': return 'INTEGER';
  61  	 	 case 'I8': return 'FIXED(20)';
  62  
  63  	 	 case 'F': return 'FLOAT(38)';
  64  	 	 case 'N': return 'FIXED';
  65  	 	 default:
  66  	 	 	 return $meta;
  67  	 	 }
  68  	 }
  69  
  70  	function MetaType($t,$len=-1,$fieldobj=false)
  71  	 {
  72  	 	 if (is_object($t)) {
  73  	 	 	 $fieldobj = $t;
  74  	 	 	 $t = $fieldobj->type;
  75  	 	 	 $len = $fieldobj->max_length;
  76  	 	 }
  77  	 	 
  78  	 	 $t = strtoupper($t);
  79  	 	 
  80  	 	 if (array_key_exists($t,$this->connection->customActualTypes))
  81  	 	 	 return  $this->connection->customActualTypes[$t];
  82  
  83  	 	 static $maxdb_type2adodb = array(
  84  	 	 	 'VARCHAR'	 => 'C',
  85  	 	 	 'CHARACTER'	 => 'C',
  86  	 	 	 'LONG'	 	 => 'X',	 	 // no way to differ between 'X' and 'B' :-(
  87  	 	 	 'DATE'	 	 => 'D',
  88  	 	 	 'TIMESTAMP'	 => 'T',
  89  	 	 	 'BOOLEAN'	 => 'L',
  90  	 	 	 'INTEGER'	 => 'I4',
  91  	 	 	 'SMALLINT'	 => 'I2',
  92  	 	 	 'FLOAT'	 	 => 'F',
  93  	 	 	 'FIXED'	 	 => 'N',
  94  	 	 );
  95  	 	 $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : ADODB_DEFAULT_METATYPE;
  96  
  97  	 	 // convert integer-types simulated with fixed back to integer
  98  	 	 if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
  99  	 	 	 $type = $len == 20 ? 'I8' : 'I1';
 100  	 	 }
 101  	 	 if ($fieldobj->auto_increment) $type = 'R';
 102  
 103  	 	 return $type;
 104  	 }
 105  
 106  	 // return string must begin with space
 107  	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
 108  	 {
 109  	 	 $suffix = '';
 110  	 	 if ($funsigned) $suffix .= ' UNSIGNED';
 111  	 	 if ($fnotnull) $suffix .= ' NOT NULL';
 112  	 	 if ($fautoinc) $suffix .= ' DEFAULT SERIAL';
 113  	 	 elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
 114  	 	 if ($fconstraint) $suffix .= ' '.$fconstraint;
 115  	 	 return $suffix;
 116  	 }
 117  
 118  	function AddColumnSQL($tabname, $flds)
 119  	 {
 120  	 	 $tabname = $this->TableName ($tabname);
 121  	 	 $sql = array();
 122  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 123  	 	 return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );
 124  	 }
 125  
 126  	function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
 127  	 {
 128  	 	 $tabname = $this->TableName ($tabname);
 129  	 	 $sql = array();
 130  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 131  	 	 return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );
 132  	 }
 133  
 134  	function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
 135  	 {
 136  	 	 $tabname = $this->TableName ($tabname);
 137  	 	 if (!is_array($flds)) $flds = explode(',',$flds);
 138  	 	 foreach($flds as $k => $v) {
 139  	 	 	 $flds[$k] = $this->NameQuote($v);
 140  	 	 }
 141  	 	 return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );
 142  	 }
 143  }