C:/lib/adodb/datadict/datadict-db2.inc.php Quellcode

datadict-db2.inc.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
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 
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]) ) {
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 }
142 
143 
144 ?>




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.