Fixes to the PaintWeb cron task.
[moodle/mihaisucan.git] / lib / adodb / datadict / datadict-db2.inc.php
blob6e03b253fb087eddf527a366d7d9851e90e75128
1 <?php
3 /**
4 V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). 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 'T': return 'TIMESTAMP';
35 case 'L': return 'SMALLINT';
36 case 'I': return 'INTEGER';
37 case 'I1': return 'SMALLINT';
38 case 'I2': return 'SMALLINT';
39 case 'I4': return 'INTEGER';
40 case 'I8': return 'BIGINT';
42 case 'F': return 'DOUBLE';
43 case 'N': return 'DECIMAL';
44 default:
45 return $meta;
49 // return string must begin with space
50 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
52 $suffix = '';
53 if ($fautoinc) return ' GENERATED ALWAYS AS IDENTITY'; # as identity start with
54 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
55 if ($fnotnull) $suffix .= ' NOT NULL';
56 if ($fconstraint) $suffix .= ' '.$fconstraint;
57 return $suffix;
60 function AlterColumnSQL($tabname, $flds)
62 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
63 return array();
67 function DropColumnSQL($tabname, $flds)
69 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
70 return array();
74 function ChangeTableSQL($tablename, $flds, $tableoptions = false)
77 /**
78 Allow basic table changes to DB2 databases
79 DB2 will fatally reject changes to non character columns
83 $validTypes = array("CHAR","VARC");
84 $invalidTypes = array("BIGI","BLOB","CLOB","DATE", "DECI","DOUB", "INTE", "REAL","SMAL", "TIME");
85 // check table exists
86 $cols = &$this->MetaColumns($tablename);
87 if ( empty($cols)) {
88 return $this->CreateTableSQL($tablename, $flds, $tableoptions);
91 // already exists, alter table instead
92 list($lines,$pkey) = $this->_GenFields($flds);
93 $alter = 'ALTER TABLE ' . $this->TableName($tablename);
94 $sql = array();
96 foreach ( $lines as $id => $v ) {
97 if ( isset($cols[$id]) && is_object($cols[$id]) ) {
98 /**
99 If the first field of $v is the fieldname, and
100 the second is the field type/size, we assume its an
101 attempt to modify the column size, so check that it is allowed
102 $v can have an indeterminate number of blanks between the
103 fields, so account for that too
105 $vargs = explode(' ' , $v);
106 // assume that $vargs[0] is the field name.
107 $i=0;
108 // Find the next non-blank value;
109 for ($i=1;$i<sizeof($vargs);$i++)
110 if ($vargs[$i] != '')
111 break;
113 // if $vargs[$i] is one of the following, we are trying to change the
114 // size of the field, if not allowed, simply ignore the request.
115 if (in_array(substr($vargs[$i],0,4),$invalidTypes))
116 continue;
117 // insert the appropriate DB2 syntax
118 if (in_array(substr($vargs[$i],0,4),$validTypes)) {
119 array_splice($vargs,$i,0,array('SET','DATA','TYPE'));
122 // Now Look for the NOT NULL statement as this is not allowed in
123 // the ALTER table statement. If it is in there, remove it
124 if (in_array('NOT',$vargs) && in_array('NULL',$vargs)) {
125 for ($i=1;$i<sizeof($vargs);$i++)
126 if ($vargs[$i] == 'NOT')
127 break;
128 array_splice($vargs,$i,2,'');
130 $v = implode(' ',$vargs);
131 $sql[] = $alter . $this->alterCol . ' ' . $v;
132 } else {
133 $sql[] = $alter . $this->addCol . ' ' . $v;
137 return $sql;