[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/adodb/datadict/ -> datadict-db2.inc.php (source)

   1  <?php
   2  
   3  /**
   4    V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
   5    Released under both BSD license and Lesser GPL library license.
   6    Whenever there is any discrepancy between the two licenses,
   7    the BSD license will take precedence.
   8  
   9    Set tabs to 4 for best viewing.
  10  
  11  */
  12  // security - hide paths
  13  if (!defined('ADODB_DIR')) die();
  14  
  15  class ADODB2_db2 extends ADODB_DataDict {
  16  
  17      var $databaseType = 'db2';
  18      var $seqField = false;
  19  
  20   	function ActualType($meta)
  21      {
  22          switch($meta) {
  23          case 'C': return 'VARCHAR';
  24          case 'XL': return 'CLOB';
  25          case 'X': return 'VARCHAR(3600)';
  26  
  27          case 'C2': return 'VARCHAR'; // up to 32K
  28          case 'X2': return 'VARCHAR(3600)'; // up to 32000, but default page size too small
  29  
  30          case 'B': return 'BLOB';
  31  
  32          case 'D': return 'DATE';
  33          case 'TS':
  34          case 'T': return 'TIMESTAMP';
  35  
  36          case 'L': return 'SMALLINT';
  37          case 'I': return 'INTEGER';
  38          case 'I1': return 'SMALLINT';
  39          case 'I2': return 'SMALLINT';
  40          case 'I4': return 'INTEGER';
  41          case 'I8': return 'BIGINT';
  42  
  43          case 'F': return 'DOUBLE';
  44          case 'N': return 'DECIMAL';
  45          default:
  46              return $meta;
  47          }
  48      }
  49  
  50      // return string must begin with space
  51  	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
  52      {
  53          $suffix = '';
  54          if ($fautoinc) return ' GENERATED ALWAYS AS IDENTITY'; # as identity start with
  55          if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
  56          if ($fnotnull) $suffix .= ' NOT NULL';
  57          if ($fconstraint) $suffix .= ' '.$fconstraint;
  58          return $suffix;
  59      }
  60  
  61  	function AlterColumnSQL($tabname, $flds)
  62      {
  63          if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
  64          return array();
  65      }
  66  
  67  
  68  	function DropColumnSQL($tabname, $flds)
  69      {
  70          if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
  71          return array();
  72      }
  73  
  74  
  75  	function ChangeTableSQL($tablename, $flds, $tableoptions = false)
  76      {
  77  
  78          /**
  79            Allow basic table changes to DB2 databases
  80            DB2 will fatally reject changes to non character columns
  81  
  82          */
  83  
  84          $validTypes = array("CHAR","VARC");
  85          $invalidTypes = array("BIGI","BLOB","CLOB","DATE", "DECI","DOUB", "INTE", "REAL","SMAL", "TIME");
  86          // check table exists
  87          $cols = $this->MetaColumns($tablename);
  88          if ( empty($cols)) {
  89              return $this->CreateTableSQL($tablename, $flds, $tableoptions);
  90          }
  91  
  92          // already exists, alter table instead
  93          list($lines,$pkey) = $this->_GenFields($flds);
  94          $alter = 'ALTER TABLE ' . $this->TableName($tablename);
  95          $sql = array();
  96  
  97          foreach ( $lines as $id => $v ) {
  98              if ( isset($cols[$id]) && is_object($cols[$id]) ) {
  99                  /**
 100                    If the first field of $v is the fieldname, and
 101                    the second is the field type/size, we assume its an
 102                    attempt to modify the column size, so check that it is allowed
 103                    $v can have an indeterminate number of blanks between the
 104                    fields, so account for that too
 105                   */
 106                  $vargs = explode(' ' , $v);
 107                  // assume that $vargs[0] is the field name.
 108                  $i=0;
 109                  // Find the next non-blank value;
 110                  for ($i=1;$i<sizeof($vargs);$i++)
 111                      if ($vargs[$i] != '')
 112                          break;
 113  
 114                  // if $vargs[$i] is one of the following, we are trying to change the
 115                  // size of the field, if not allowed, simply ignore the request.
 116                  if (in_array(substr($vargs[$i],0,4),$invalidTypes))
 117                      continue;
 118                  // insert the appropriate DB2 syntax
 119                  if (in_array(substr($vargs[$i],0,4),$validTypes)) {
 120                      array_splice($vargs,$i,0,array('SET','DATA','TYPE'));
 121                  }
 122  
 123                  // Now Look for the NOT NULL statement as this is not allowed in
 124                  // the ALTER table statement. If it is in there, remove it
 125                  if (in_array('NOT',$vargs) && in_array('NULL',$vargs)) {
 126                      for ($i=1;$i<sizeof($vargs);$i++)
 127                      if ($vargs[$i] == 'NOT')
 128                          break;
 129                      array_splice($vargs,$i,2,'');
 130                  }
 131                  $v = implode(' ',$vargs);
 132                  $sql[] = $alter . $this->alterCol . ' ' . $v;
 133              } else {
 134                  $sql[] = $alter . $this->addCol . ' ' . $v;
 135              }
 136          }
 137  
 138          return $sql;
 139      }
 140  
 141  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1