updated adodb package to work with php 7.1
[openemr.git] / vendor / adodb / adodb-php / datadict / datadict-db2.inc.php
blob7d201ff17bf929dd2a3a474d3568d2bd9d54abcf
1 <?php
3 /**
4 @version v5.20.9 21-Dec-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.
11 Set tabs to 4 for best viewing.
14 // security - hide paths
15 if (!defined('ADODB_DIR')) die();
17 class ADODB2_db2 extends ADODB_DataDict {
19 var $databaseType = 'db2';
20 var $seqField = false;
22 function ActualType($meta)
24 switch($meta) {
25 case 'C': return 'VARCHAR';
26 case 'XL': return 'CLOB';
27 case 'X': return 'VARCHAR(3600)';
29 case 'C2': return 'VARCHAR'; // up to 32K
30 case 'X2': return 'VARCHAR(3600)'; // up to 32000, but default page size too small
32 case 'B': return 'BLOB';
34 case 'D': return 'DATE';
35 case 'TS':
36 case 'T': return 'TIMESTAMP';
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';
45 case 'F': return 'DOUBLE';
46 case 'N': return 'DECIMAL';
47 default:
48 return $meta;
52 // return string must begin with space
53 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
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;
63 function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
65 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
66 return array();
70 function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
72 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
73 return array();
77 function ChangeTableSQL($tablename, $flds, $tableoptions = false)
80 /**
81 Allow basic table changes to DB2 databases
82 DB2 will fatally reject changes to non character columns
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);
94 // already exists, alter table instead
95 list($lines,$pkey) = $this->_GenFields($flds);
96 $alter = 'ALTER TABLE ' . $this->TableName($tablename);
97 $sql = array();
99 foreach ( $lines as $id => $v ) {
100 if ( isset($cols[$id]) && is_object($cols[$id]) ) {
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
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;
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'));
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,'');
133 $v = implode(' ',$vargs);
134 $sql[] = $alter . $this->alterCol . ' ' . $v;
135 } else {
136 $sql[] = $alter . $this->addCol . ' ' . $v;
140 return $sql;