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 SyBase.
   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_sybase extends ADODB_DataDict {
  26  	 var $databaseType = 'sybase';
  27  
  28  	 var $dropIndex = 'DROP INDEX %2$s.%1$s';
  29  
  30  	function MetaType($t,$len=-1,$fieldobj=false)
  31  	 {
  32  	 	 if (is_object($t)) {
  33  	 	 	 $fieldobj = $t;
  34  	 	 	 $t = $fieldobj->type;
  35  	 	 	 $len = $fieldobj->max_length;
  36  	 	 }
  37  
  38  	 	 $len = -1; // mysql max_length is not accurate
  39  	 	 switch (strtoupper($t)) {
  40  
  41  	 	 case 'INT':
  42  	 	 case 'INTEGER': return  'I';
  43  	 	 case 'BIT':
  44  	 	 case 'TINYINT': return  'I1';
  45  	 	 case 'SMALLINT': return 'I2';
  46  	 	 case 'BIGINT':  return  'I8';
  47  
  48  	 	 case 'REAL':
  49  	 	 case 'FLOAT': return 'F';
  50  	 	 default: return parent::MetaType($t,$len,$fieldobj);
  51  	 	 }
  52  	 }
  53  
  54  	function ActualType($meta)
  55  	 {
  56  	 	 switch(strtoupper($meta)) {
  57  	 	 case 'C': return 'VARCHAR';
  58  	 	 case 'XL':
  59  	 	 case 'X': return 'TEXT';
  60  
  61  	 	 case 'C2': return 'NVARCHAR';
  62  	 	 case 'X2': return 'NTEXT';
  63  
  64  	 	 case 'B': return 'IMAGE';
  65  
  66  	 	 case 'D': return 'DATETIME';
  67  	 	 case 'TS':
  68  	 	 case 'T': return 'DATETIME';
  69  	 	 case 'L': return 'BIT';
  70  
  71  	 	 case 'I': return 'INT';
  72  	 	 case 'I1': return 'TINYINT';
  73  	 	 case 'I2': return 'SMALLINT';
  74  	 	 case 'I4': return 'INT';
  75  	 	 case 'I8': return 'BIGINT';
  76  
  77  	 	 case 'F': return 'REAL';
  78  	 	 case 'N': return 'NUMERIC';
  79  	 	 default:
  80  	 	 	 return $meta;
  81  	 	 }
  82  	 }
  83  
  84  
  85  	function AddColumnSQL($tabname, $flds)
  86  	 {
  87  	 	 $tabname = $this->TableName ($tabname);
  88  	 	 $f = array();
  89  	 	 list($lines,$pkey) = $this->_GenFields($flds);
  90  	 	 $s = "ALTER TABLE $tabname $this->addCol";
  91  	 	 foreach($lines as $v) {
  92  	 	 	 $f[] = "\n $v";
  93  	 	 }
  94  	 	 $s .= implode(', ',$f);
  95  	 	 $sql[] = $s;
  96  	 	 return $sql;
  97  	 }
  98  
  99  	function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
 100  	 {
 101  	 	 $tabname = $this->TableName ($tabname);
 102  	 	 $sql = array();
 103  	 	 list($lines,$pkey) = $this->_GenFields($flds);
 104  	 	 foreach($lines as $v) {
 105  	 	 	 $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
 106  	 	 }
 107  
 108  	 	 return $sql;
 109  	 }
 110  
 111  	function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
 112  	 {
 113  	 	 $tabname = $this->TableName($tabname);
 114  	 	 if (!is_array($flds)) $flds = explode(',',$flds);
 115  	 	 $f = array();
 116  	 	 $s = "ALTER TABLE $tabname";
 117  	 	 foreach($flds as $v) {
 118  	 	 	 $f[] = "\n$this->dropCol ".$this->NameQuote($v);
 119  	 	 }
 120  	 	 $s .= implode(', ',$f);
 121  	 	 $sql[] = $s;
 122  	 	 return $sql;
 123  	 }
 124  
 125  	 // return string must begin with space
 126  	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
 127  	 {
 128  	 	 $suffix = '';
 129  	 	 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
 130  	 	 if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
 131  	 	 if ($fnotnull) $suffix .= ' NOT NULL';
 132  	 	 else if ($suffix == '') $suffix .= ' NULL';
 133  	 	 if ($fconstraint) $suffix .= ' '.$fconstraint;
 134  	 	 return $suffix;
 135  	 }
 136  
 137  	 /*
 138  CREATE TABLE
 139      [ database_name.[ owner ] . | owner. ] table_name
 140      ( { < column_definition >
 141          | column_name AS computed_column_expression
 142          | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
 143  
 144              | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
 145      )
 146  
 147  [ ON { filegroup | DEFAULT } ]
 148  [ TEXTIMAGE_ON { filegroup | DEFAULT } ]
 149  
 150  < column_definition > ::= { column_name data_type }
 151      [ COLLATE < collation_name > ]
 152      [ [ DEFAULT constant_expression ]
 153          | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
 154      ]
 155      [ ROWGUIDCOL]
 156      [ < column_constraint > ] [ ...n ]
 157  
 158  < column_constraint > ::= [ CONSTRAINT constraint_name ]
 159      { [ NULL | NOT NULL ]
 160          | [ { PRIMARY KEY | UNIQUE }
 161              [ CLUSTERED | NONCLUSTERED ]
 162              [ WITH FILLFACTOR = fillfactor ]
 163              [ON {filegroup | DEFAULT} ] ]
 164          ]
 165          | [ [ FOREIGN KEY ]
 166              REFERENCES ref_table [ ( ref_column ) ]
 167              [ ON DELETE { CASCADE | NO ACTION } ]
 168              [ ON UPDATE { CASCADE | NO ACTION } ]
 169              [ NOT FOR REPLICATION ]
 170          ]
 171          | CHECK [ NOT FOR REPLICATION ]
 172          ( logical_expression )
 173      }
 174  
 175  < table_constraint > ::= [ CONSTRAINT constraint_name ]
 176      { [ { PRIMARY KEY | UNIQUE }
 177          [ CLUSTERED | NONCLUSTERED ]
 178          { ( column [ ASC | DESC ] [ ,...n ] ) }
 179          [ WITH FILLFACTOR = fillfactor ]
 180          [ ON { filegroup | DEFAULT } ]
 181      ]
 182      | FOREIGN KEY
 183          [ ( column [ ,...n ] ) ]
 184          REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
 185          [ ON DELETE { CASCADE | NO ACTION } ]
 186          [ ON UPDATE { CASCADE | NO ACTION } ]
 187          [ NOT FOR REPLICATION ]
 188      | CHECK [ NOT FOR REPLICATION ]
 189          ( search_conditions )
 190      }
 191  
 192  
 193  	 */
 194  
 195  	 /*
 196  	 CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
 197      ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
 198  	 	 [ WITH < index_option > [ ,...n] ]
 199  	 	 [ ON filegroup ]
 200  	 	 < index_option > :: =
 201  	 	     { PAD_INDEX |
 202  	 	         FILLFACTOR = fillfactor |
 203  	 	         IGNORE_DUP_KEY |
 204  	 	         DROP_EXISTING |
 205  	 	     STATISTICS_NORECOMPUTE |
 206  	 	     SORT_IN_TEMPDB
 207  	 	 }
 208  */
 209  	function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
 210  	 {
 211  	 	 $sql = array();
 212  
 213  	 	 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
 214  	 	 	 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
 215  	 	 	 if ( isset($idxoptions['DROP']) )
 216  	 	 	 	 return $sql;
 217  	 	 }
 218  
 219  	 	 if ( empty ($flds) ) {
 220  	 	 	 return $sql;
 221  	 	 }
 222  
 223  	 	 $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
 224  	 	 $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
 225  
 226  	 	 if ( is_array($flds) )
 227  	 	 	 $flds = implode(', ',$flds);
 228  	 	 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
 229  
 230  	 	 if ( isset($idxoptions[$this->upperName]) )
 231  	 	 	 $s .= $idxoptions[$this->upperName];
 232  
 233  	 	 $sql[] = $s;
 234  
 235  	 	 return $sql;
 236  	 }
 237  }