Changeset 34 for trunk/phpgwapi/inc/adodb/datadict/datadict-db2.inc.php
- Timestamp:
- 06/29/07 15:17:46 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpgwapi/inc/adodb/datadict/datadict-db2.inc.php
r2 r34 2 2 3 3 /** 4 V4. 51 29 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.4 V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 5 5 Released under both BSD license and Lesser GPL library license. 6 6 Whenever there is any discrepancy between the two licenses, … … 17 17 var $databaseType = 'db2'; 18 18 var $seqField = false; 19 19 20 20 function ActualType($meta) 21 21 { … … 24 24 case 'XL': return 'CLOB'; 25 25 case 'X': return 'VARCHAR(3600)'; 26 26 27 27 case 'C2': return 'VARCHAR'; // up to 32K 28 28 case 'X2': return 'VARCHAR(3600)'; // up to 32000, but default page size too small 29 29 30 30 case 'B': return 'BLOB'; 31 31 32 32 case 'D': return 'DATE'; 33 33 case 'T': return 'TIMESTAMP'; 34 34 35 35 case 'L': return 'SMALLINT'; 36 36 case 'I': return 'INTEGER'; … … 39 39 case 'I4': return 'INTEGER'; 40 40 case 'I8': return 'BIGINT'; 41 41 42 42 case 'F': return 'DOUBLE'; 43 43 case 'N': return 'DECIMAL'; … … 71 71 } 72 72 73 74 function ChangeTableSQL($tablename, $flds, $tableoptions = false) 75 { 76 77 /** 78 Allow basic table changes to DB2 databases 79 DB2 will fatally reject changes to non character columns 80 81 */ 82 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); 89 } 90 91 // already exists, alter table instead 92 list($lines,$pkey) = $this->_GenFields($flds); 93 $alter = 'ALTER TABLE ' . $this->TableName($tablename); 94 $sql = array(); 95 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 104 */ 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; 112 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')); 120 } 121 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,''); 129 } 130 $v = implode(' ',$vargs); 131 $sql[] = $alter . $this->alterCol . ' ' . $v; 132 } else { 133 $sql[] = $alter . $this->addCol . ' ' . $v; 134 } 135 } 136 137 return $sql; 138 } 139 73 140 } 74 141
Note: See TracChangeset
for help on using the changeset viewer.