Documentation TYPO3 par Ameos

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 'T': return 'TIMESTAMP';
00034 
00035                 case 'L': return 'SMALLINT';
00036                 case 'I': return 'INTEGER';
00037                 case 'I1': return 'SMALLINT';
00038                 case 'I2': return 'SMALLINT';
00039                 case 'I4': return 'INTEGER';
00040                 case 'I8': return 'BIGINT';
00041 
00042                 case 'F': return 'DOUBLE';
00043                 case 'N': return 'DECIMAL';
00044                 default:
00045                         return $meta;
00046                 }
00047         }
00048         
00049         // return string must begin with space
00050         function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
00051         {       
00052                 $suffix = '';
00053                 if ($fautoinc) return ' GENERATED ALWAYS AS IDENTITY'; # as identity start with 
00054                 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00055                 if ($fnotnull) $suffix .= ' NOT NULL';
00056                 if ($fconstraint) $suffix .= ' '.$fconstraint;
00057                 return $suffix;
00058         }
00059 
00060         function AlterColumnSQL($tabname, $flds)
00061         {
00062                 if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
00063                 return array();
00064         }
00065         
00066         
00067         function DropColumnSQL($tabname, $flds)
00068         {
00069                 if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
00070                 return array();
00071         }
00072         
00073         
00074         function ChangeTableSQL($tablename, $flds, $tableoptions = false)
00075         {
00076                 
00083                 $validTypes = array("CHAR","VARC");
00084                 $invalidTypes = array("BIGI","BLOB","CLOB","DATE", "DECI","DOUB", "INTE", "REAL","SMAL", "TIME");
00085                 // check table exists
00086                 $cols = &$this->MetaColumns($tablename);
00087                 if ( empty($cols)) { 
00088                         return $this->CreateTableSQL($tablename, $flds, $tableoptions);
00089                 }
00090                 
00091                 // already exists, alter table instead
00092                 list($lines,$pkey) = $this->_GenFields($flds);
00093                 $alter = 'ALTER TABLE ' . $this->TableName($tablename);
00094                 $sql = array();
00095                 
00096                 foreach ( $lines as $id => $v ) {
00097                         if ( isset($cols[$id]) && is_object($cols[$id]) ) {
00105                                 $vargs = explode(' ' , $v);
00106                                 // assume that $vargs[0] is the field name.
00107                                 $i=0;
00108                                 // Find the next non-blank value;
00109                                 for ($i=1;$i<sizeof($vargs);$i++)
00110                                         if ($vargs[$i] != '')
00111                                                 break;
00112                                 
00113                                 // if $vargs[$i] is one of the following, we are trying to change the
00114                                 // size of the field, if not allowed, simply ignore the request.
00115                                 if (in_array(substr($vargs[$i],0,4),$invalidTypes)) 
00116                                         continue;
00117                                 // insert the appropriate DB2 syntax
00118                                 if (in_array(substr($vargs[$i],0,4),$validTypes)) {
00119                                         array_splice($vargs,$i,0,array('SET','DATA','TYPE'));
00120                                 }
00121 
00122                                 // Now Look for the NOT NULL statement as this is not allowed in
00123                                 // the ALTER table statement. If it is in there, remove it
00124                                 if (in_array('NOT',$vargs) && in_array('NULL',$vargs)) {
00125                                         for ($i=1;$i<sizeof($vargs);$i++)
00126                                         if ($vargs[$i] == 'NOT')
00127                                                 break;
00128                                         array_splice($vargs,$i,2,'');
00129                                 }
00130                                 $v = implode(' ',$vargs);       
00131                                 $sql[] = $alter . $this->alterCol . ' ' . $v;
00132                         } else {
00133                                 $sql[] = $alter . $this->addCol . ' ' . $v;
00134                         }
00135                 }
00136                 
00137                 return $sql;
00138         }
00139         
00140 }
00141 
00142 
00143 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6