[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1