Adodb Dokumentation  V5.14 8 Sept 2011
datadict/datadict-db2.inc.php
00001 <?php
00002 
00012 // security - hide paths
00013 if (!defined('ADODB_DIR')) die();
00014 
00015 class ADODB2_db2 extends ADODB_DataDict {
00016         
00017         var $databaseType = 'db2';
00018         var $seqField = false;
00019         
00020         function ActualType($meta)
00021         {
00022                 switch($meta) {
00023                 case 'C': return 'VARCHAR';
00024                 case 'XL': return 'CLOB';
00025                 case 'X': return 'VARCHAR(3600)'; 
00026 
00027                 case 'C2': return 'VARCHAR'; // up to 32K
00028                 case 'X2': return 'VARCHAR(3600)'; // up to 32000, but default page size too small
00029 
00030                 case 'B': return 'BLOB';
00031 
00032                 case 'D': return 'DATE';
00033                 case 'TS':
00034                 case 'T': return 'TIMESTAMP';
00035 
00036                 case 'L': return 'SMALLINT';
00037                 case 'I': return 'INTEGER';
00038                 case 'I1': return 'SMALLINT';
00039                 case 'I2': return 'SMALLINT';
00040                 case 'I4': return 'INTEGER';
00041                 case 'I8': return 'BIGINT';
00042 
00043                 case 'F': return 'DOUBLE';
00044                 case 'N': return 'DECIMAL';
00045                 default:
00046                         return $meta;
00047                 }
00048         }
00049         
00050         // return string must begin with space
00051         function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
00052         {       
00053                 $suffix = '';
00054                 if ($fautoinc) return ' GENERATED ALWAYS AS IDENTITY'; # as identity start with 
00055                 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00056                 if ($fnotnull) $suffix .= ' NOT NULL';
00057                 if ($fconstraint) $suffix .= ' '.$fconstraint;
00058                 return $suffix;
00059         }
00060 
00061         function AlterColumnSQL($tabname, $flds)
00062         {
00063                 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
00064                 return array();
00065         }
00066         
00067         
00068         function DropColumnSQL($tabname, $flds)
00069         {
00070                 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
00071                 return array();
00072         }
00073         
00074         
00075         function ChangeTableSQL($tablename, $flds, $tableoptions = false)
00076         {
00077                 
00084                 $validTypes = array("CHAR","VARC");
00085                 $invalidTypes = array("BIGI","BLOB","CLOB","DATE", "DECI","DOUB", "INTE", "REAL","SMAL", "TIME");
00086                 // check table exists
00087                 $cols = $this->MetaColumns($tablename);
00088                 if ( empty($cols)) { 
00089                         return $this->CreateTableSQL($tablename, $flds, $tableoptions);
00090                 }
00091                 
00092                 // already exists, alter table instead
00093                 list($lines,$pkey) = $this->_GenFields($flds);
00094                 $alter = 'ALTER TABLE ' . $this->TableName($tablename);
00095                 $sql = array();
00096                 
00097                 foreach ( $lines as $id => $v ) {
00098                         if ( isset($cols[$id]) && is_object($cols[$id]) ) {
00106                                 $vargs = explode(' ' , $v);
00107                                 // assume that $vargs[0] is the field name.
00108                                 $i=0;
00109                                 // Find the next non-blank value;
00110                                 for ($i=1;$i<sizeof($vargs);$i++)
00111                                         if ($vargs[$i] != '')
00112                                                 break;
00113                                 
00114                                 // if $vargs[$i] is one of the following, we are trying to change the
00115                                 // size of the field, if not allowed, simply ignore the request.
00116                                 if (in_array(substr($vargs[$i],0,4),$invalidTypes)) 
00117                                         continue;
00118                                 // insert the appropriate DB2 syntax
00119                                 if (in_array(substr($vargs[$i],0,4),$validTypes)) {
00120                                         array_splice($vargs,$i,0,array('SET','DATA','TYPE'));
00121                                 }
00122 
00123                                 // Now Look for the NOT NULL statement as this is not allowed in
00124                                 // the ALTER table statement. If it is in there, remove it
00125                                 if (in_array('NOT',$vargs) && in_array('NULL',$vargs)) {
00126                                         for ($i=1;$i<sizeof($vargs);$i++)
00127                                         if ($vargs[$i] == 'NOT')
00128                                                 break;
00129                                         array_splice($vargs,$i,2,'');
00130                                 }
00131                                 $v = implode(' ',$vargs);       
00132                                 $sql[] = $alter . $this->alterCol . ' ' . $v;
00133                         } else {
00134                                 $sql[] = $alter . $this->addCol . ' ' . $v;
00135                         }
00136                 }
00137                 
00138                 return $sql;
00139         }
00140         
00141 }
00142 
00143 
00144 ?>