TYPO3 CMS  TYPO3_7-6
datadict-db2.inc.php
Go to the documentation of this file.
1 <?php
2 
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 
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]) ) {
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 }
_GenFields($flds, $widespacing=false)
MetaColumns($tab, $upper=true, $schema=false)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel='E_DEBUG')
AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
ChangeTableSQL($tablename, $flds, $tableoptions=false)
CreateTableSQL($tabname, $flds, $tableoptions=array())
_CreateSuffix($fname, &$ftype, $fnotnull, $fdefault, $fautoinc, $fconstraint, $funsigned)
$sql
Definition: server.php:84