Ignore:
Timestamp:
06/29/07 15:17:46 (17 years ago)
Author:
niltonneto
Message:

Versão nova do ADODB (4.5 para 4.95)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpgwapi/inc/adodb/datadict/datadict-db2.inc.php

    r2 r34  
    22 
    33/** 
    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. 
    55  Released under both BSD license and Lesser GPL library license.  
    66  Whenever there is any discrepancy between the two licenses,  
     
    1717        var $databaseType = 'db2'; 
    1818        var $seqField = false; 
    19          
     19         
    2020        function ActualType($meta) 
    2121        { 
     
    2424                case 'XL': return 'CLOB'; 
    2525                case 'X': return 'VARCHAR(3600)';  
    26                  
     26 
    2727                case 'C2': return 'VARCHAR'; // up to 32K 
    2828                case 'X2': return 'VARCHAR(3600)'; // up to 32000, but default page size too small 
    29                  
     29 
    3030                case 'B': return 'BLOB'; 
    31                          
     31 
    3232                case 'D': return 'DATE'; 
    3333                case 'T': return 'TIMESTAMP'; 
    34                  
     34 
    3535                case 'L': return 'SMALLINT'; 
    3636                case 'I': return 'INTEGER'; 
     
    3939                case 'I4': return 'INTEGER'; 
    4040                case 'I8': return 'BIGINT'; 
    41                  
     41 
    4242                case 'F': return 'DOUBLE'; 
    4343                case 'N': return 'DECIMAL'; 
     
    7171        } 
    7272         
     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         
    73140} 
    74141 
Note: See TracChangeset for help on using the changeset viewer.