Allow switch to simpler age display format for patients above certain age
[openemr.git] / library / adodb / datadict / datadict-db2.inc.php
blob04d51e4756700b428524514bfe34e76539ede321
1 <?php
3 /**
4 V5.14 8 Sept 2011 (c) 2000-2011 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.
9 Set tabs to 4 for best viewing.
12 // security - hide paths
13 if (!defined('ADODB_DIR')) die();
15 class ADODB2_db2 extends ADODB_DataDict {
17 var $databaseType = 'db2';
18 var $seqField = false;
20 function ActualType($meta)
22 switch($meta) {
23 case 'C': return 'VARCHAR';
24 case 'XL': return 'CLOB';
25 case 'X': return 'VARCHAR(3600)';
27 case 'C2': return 'VARCHAR'; // up to 32K
28 case 'X2': return 'VARCHAR(3600)'; // up to 32000, but default page size too small
30 case 'B': return 'BLOB';
32 case 'D': return 'DATE';
33 case 'TS':
34 case 'T': return 'TIMESTAMP';
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';
43 case 'F': return 'DOUBLE';
44 case 'N': return 'DECIMAL';
45 default:
46 return $meta;
50 // return string must begin with space
51 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
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;
61 function AlterColumnSQL($tabname, $flds)
63 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
64 return array();
68 function DropColumnSQL($tabname, $flds)
70 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
71 return array();
75 function ChangeTableSQL($tablename, $flds, $tableoptions = false)
78 /**
79 Allow basic table changes to DB2 databases
80 DB2 will fatally reject changes to non character columns
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);
92 // already exists, alter table instead
93 list($lines,$pkey) = $this->_GenFields($flds);
94 $alter = 'ALTER TABLE ' . $this->TableName($tablename);
95 $sql = array();
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
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;
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'));
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,'');
131 $v = implode(' ',$vargs);
132 $sql[] = $alter . $this->alterCol . ' ' . $v;
133 } else {
134 $sql[] = $alter . $this->addCol . ' ' . $v;
138 return $sql;