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/adodb-datadict.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,  
     
    2323function Lens_ParseTest() 
    2424{ 
    25 $str = "`zcol ACOL` NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0"; 
     25$str = "`zcol ACOL` NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0, zcol2\"afs ds"; 
    2626print "<p>$str</p>"; 
    2727$a= Lens_ParseArgs($str); 
     
    3030print "</pre>"; 
    3131} 
     32 
    3233 
    3334if (!function_exists('ctype_alnum')) { 
     
    6162        $max = strlen($args); 
    6263        $quoted = false; 
     64        $tokarr = array(); 
    6365         
    6466        while ($pos < $max) { 
     
    154156                $pos += 1; 
    155157        } 
     158        if ($intoken) $tokens[$stmtno][] = implode('',$tokarr); 
    156159         
    157160        return $tokens; 
     
    163166        var $debug = false; 
    164167        var $dropTable = 'DROP TABLE %s'; 
     168        var $renameTable = 'RENAME TABLE %s TO %s';  
    165169        var $dropIndex = 'DROP INDEX %s'; 
    166170        var $addCol = ' ADD'; 
    167171        var $alterCol = ' ALTER COLUMN'; 
    168172        var $dropCol = ' DROP COLUMN'; 
     173        var $renameColumn = 'ALTER TABLE %s RENAME COLUMN %s TO %s';    // table, old-column, new-column, column-definitions (not used by default) 
    169174        var $nameRegex = '\w'; 
     175        var $nameRegexBrackets = 'a-zA-Z0-9_\(\)'; 
    170176        var $schema = false; 
    171177        var $serverInfo = array(); 
    172178        var $autoIncrement = false; 
    173179        var $dataProvider; 
     180        var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql 
    174181        var $blobSize = 100;    /// any varchar/char field this size or greater is treated as a blob 
    175182                                                        /// in other words, we use a text area for editting. 
     
    185192        } 
    186193         
    187         function &MetaTables() 
    188         { 
     194        function MetaTables() 
     195        { 
     196                if (!$this->connection->IsConnected()) return array(); 
    189197                return $this->connection->MetaTables(); 
    190198        } 
    191199         
    192         function &MetaColumns($tab, $upper=true, $schema=false) 
    193         { 
     200        function MetaColumns($tab, $upper=true, $schema=false) 
     201        { 
     202                if (!$this->connection->IsConnected()) return array(); 
    194203                return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema); 
    195204        } 
    196205         
    197         function &MetaPrimaryKeys($tab,$owner=false,$intkey=false) 
    198         { 
     206        function MetaPrimaryKeys($tab,$owner=false,$intkey=false) 
     207        { 
     208                if (!$this->connection->IsConnected()) return array(); 
    199209                return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey); 
    200210        } 
    201211         
    202         function &MetaIndexes($table, $primary = false, $owner = false) 
    203         { 
     212        function MetaIndexes($table, $primary = false, $owner = false) 
     213        { 
     214                if (!$this->connection->IsConnected()) return array(); 
    204215                return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner); 
    205216        } 
    206217         
     218 
    207219        function MetaType($t,$len=-1,$fieldobj=false) 
    208         { 
    209                 return ADORecordSet::MetaType($t,$len,$fieldobj); 
    210         } 
    211          
    212         function NameQuote($name = NULL) 
     220        {                
     221                static $typeMap = array( 
     222                'VARCHAR' => 'C', 
     223                'VARCHAR2' => 'C', 
     224                'CHAR' => 'C', 
     225                'C' => 'C', 
     226                'STRING' => 'C', 
     227                'NCHAR' => 'C', 
     228                'NVARCHAR' => 'C', 
     229                'VARYING' => 'C', 
     230                'BPCHAR' => 'C', 
     231                'CHARACTER' => 'C', 
     232                'INTERVAL' => 'C',  # Postgres 
     233                'MACADDR' => 'C', # postgres 
     234                ## 
     235                'LONGCHAR' => 'X', 
     236                'TEXT' => 'X', 
     237                'NTEXT' => 'X', 
     238                'M' => 'X', 
     239                'X' => 'X', 
     240                'CLOB' => 'X', 
     241                'NCLOB' => 'X', 
     242                'LVARCHAR' => 'X', 
     243                ## 
     244                'BLOB' => 'B', 
     245                'IMAGE' => 'B', 
     246                'BINARY' => 'B', 
     247                'VARBINARY' => 'B', 
     248                'LONGBINARY' => 'B', 
     249                'B' => 'B', 
     250                ## 
     251                'YEAR' => 'D', // mysql 
     252                'DATE' => 'D', 
     253                'D' => 'D', 
     254                ## 
     255                'UNIQUEIDENTIFIER' => 'C', # MS SQL Server 
     256                ## 
     257                'TIME' => 'T', 
     258                'TIMESTAMP' => 'T', 
     259                'DATETIME' => 'T', 
     260                'TIMESTAMPTZ' => 'T', 
     261                'T' => 'T', 
     262                'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql 
     263                ## 
     264                'BOOL' => 'L', 
     265                'BOOLEAN' => 'L',  
     266                'BIT' => 'L', 
     267                'L' => 'L', 
     268                ## 
     269                'COUNTER' => 'R', 
     270                'R' => 'R', 
     271                'SERIAL' => 'R', // ifx 
     272                'INT IDENTITY' => 'R', 
     273                ## 
     274                'INT' => 'I', 
     275                'INT2' => 'I', 
     276                'INT4' => 'I', 
     277                'INT8' => 'I', 
     278                'INTEGER' => 'I', 
     279                'INTEGER UNSIGNED' => 'I', 
     280                'SHORT' => 'I', 
     281                'TINYINT' => 'I', 
     282                'SMALLINT' => 'I', 
     283                'I' => 'I', 
     284                ## 
     285                'LONG' => 'N', // interbase is numeric, oci8 is blob 
     286                'BIGINT' => 'N', // this is bigger than PHP 32-bit integers 
     287                'DECIMAL' => 'N', 
     288                'DEC' => 'N', 
     289                'REAL' => 'N', 
     290                'DOUBLE' => 'N', 
     291                'DOUBLE PRECISION' => 'N', 
     292                'SMALLFLOAT' => 'N', 
     293                'FLOAT' => 'N', 
     294                'NUMBER' => 'N', 
     295                'NUM' => 'N', 
     296                'NUMERIC' => 'N', 
     297                'MONEY' => 'N', 
     298                 
     299                ## informix 9.2 
     300                'SQLINT' => 'I',  
     301                'SQLSERIAL' => 'I',  
     302                'SQLSMINT' => 'I',  
     303                'SQLSMFLOAT' => 'N',  
     304                'SQLFLOAT' => 'N',  
     305                'SQLMONEY' => 'N',  
     306                'SQLDECIMAL' => 'N',  
     307                'SQLDATE' => 'D',  
     308                'SQLVCHAR' => 'C',  
     309                'SQLCHAR' => 'C',  
     310                'SQLDTIME' => 'T',  
     311                'SQLINTERVAL' => 'N',  
     312                'SQLBYTES' => 'B',  
     313                'SQLTEXT' => 'X', 
     314                 ## informix 10 
     315                "SQLINT8" => 'I8', 
     316                "SQLSERIAL8" => 'I8', 
     317                "SQLNCHAR" => 'C', 
     318                "SQLNVCHAR" => 'C', 
     319                "SQLLVARCHAR" => 'X', 
     320                "SQLBOOL" => 'L' 
     321                ); 
     322                 
     323                if (!$this->connection->IsConnected()) { 
     324                        $t = strtoupper($t); 
     325                        if (isset($typeMap[$t])) return $typeMap[$t]; 
     326                        return 'N'; 
     327                } 
     328                return $this->connection->MetaType($t,$len,$fieldobj); 
     329        } 
     330         
     331        function NameQuote($name = NULL,$allowBrackets=false) 
    213332        { 
    214333                if (!is_string($name)) { 
     
    230349                 
    231350                // if name contains special characters, quote it 
    232                 if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) { 
     351                $regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex; 
     352                 
     353                if ( !preg_match('/^[' . $regex . ']+$/', $name) ) { 
    233354                        return $quote . $name . $quote; 
    234355                } 
     
    265386        } 
    266387         
    267         /* 
     388        /** 
    268389                Returns the actual type given a character code. 
    269390                 
     
    311432                 
    312433                foreach($flds as $key => $fld) { 
    313                         $flds[$key] = $this->NameQuote($fld); 
     434                        # some indexes can use partial fields, eg. index first 32 chars of "name" with NAME(32) 
     435                        $flds[$key] = $this->NameQuote($fld,$allowBrackets=true); 
    314436                } 
    315437                 
     
    331453                $tabname = $this->TableName ($tabname); 
    332454                $sql = array(); 
    333                 list($lines,$pkey) = $this->_GenFields($flds); 
     455                list($lines,$pkey,$idxs) = $this->_GenFields($flds); 
     456                // genfields can return FALSE at times 
     457                if ($lines  == null) $lines = array(); 
    334458                $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; 
    335459                foreach($lines as $v) { 
    336460                        $sql[] = $alter . $v; 
    337461                } 
     462                if (is_array($idxs)) { 
     463                        foreach($idxs as $idx => $idxdef) { 
     464                                $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); 
     465                                $sql = array_merge($sql, $sql_idxs); 
     466                        } 
     467                } 
    338468                return $sql; 
    339469        } 
    340470         
    341         function AlterColumnSQL($tabname, $flds) 
     471        /** 
     472         * Change the definition of one column 
     473         * 
     474         * As some DBM's can't do that on there own, you need to supply the complete defintion of the new table, 
     475         * to allow, recreating the table and copying the content over to the new table 
     476         * @param string $tabname table-name 
     477         * @param string $flds column-name and type for the changed column 
     478         * @param string $tableflds='' complete defintion of the new table, eg. for postgres, default '' 
     479         * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' 
     480         * @return array with SQL strings 
     481         */ 
     482        function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') 
    342483        { 
    343484                $tabname = $this->TableName ($tabname); 
    344485                $sql = array(); 
    345                 list($lines,$pkey) = $this->_GenFields($flds); 
     486                list($lines,$pkey,$idxs) = $this->_GenFields($flds); 
     487                // genfields can return FALSE at times 
     488                if ($lines == null) $lines = array(); 
    346489                $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; 
    347490                foreach($lines as $v) { 
    348491                        $sql[] = $alter . $v; 
    349492                } 
     493                if (is_array($idxs)) { 
     494                        foreach($idxs as $idx => $idxdef) { 
     495                                $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); 
     496                                $sql = array_merge($sql, $sql_idxs); 
     497                        } 
     498 
     499                } 
    350500                return $sql; 
    351501        } 
    352502         
    353         function DropColumnSQL($tabname, $flds) 
     503        /** 
     504         * Rename one column 
     505         * 
     506         * Some DBM's can only do this together with changeing the type of the column (even if that stays the same, eg. mysql) 
     507         * @param string $tabname table-name 
     508         * @param string $oldcolumn column-name to be renamed 
     509         * @param string $newcolumn new column-name 
     510         * @param string $flds='' complete column-defintion-string like for AddColumnSQL, only used by mysql atm., default='' 
     511         * @return array with SQL strings 
     512         */ 
     513        function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='') 
     514        { 
     515                $tabname = $this->TableName ($tabname); 
     516                if ($flds) { 
     517                        list($lines,$pkey,$idxs) = $this->_GenFields($flds); 
     518                        // genfields can return FALSE at times 
     519                        if ($lines == null) $lines = array(); 
     520                        list(,$first) = each($lines); 
     521                        list(,$column_def) = split("[\t ]+",$first,2); 
     522                } 
     523                return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def)); 
     524        } 
     525                 
     526        /** 
     527         * Drop one column 
     528         * 
     529         * Some DBM's can't do that on there own, you need to supply the complete defintion of the new table, 
     530         * to allow, recreating the table and copying the content over to the new table 
     531         * @param string $tabname table-name 
     532         * @param string $flds column-name and type for the changed column 
     533         * @param string $tableflds='' complete defintion of the new table, eg. for postgres, default '' 
     534         * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' 
     535         * @return array with SQL strings 
     536         */ 
     537        function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') 
    354538        { 
    355539                $tabname = $this->TableName ($tabname); 
     
    368552        } 
    369553         
    370         /* 
     554        function RenameTableSQL($tabname,$newname) 
     555        { 
     556                return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); 
     557        }        
     558         
     559        /** 
    371560         Generate the SQL to create table. Returns an array of sql strings. 
    372561        */ 
    373         function CreateTableSQL($tabname, $flds, $tableoptions=false) 
    374         { 
    375                 if (!$tableoptions) $tableoptions = array(); 
    376                  
    377                 list($lines,$pkey) = $this->_GenFields($flds); 
     562        function CreateTableSQL($tabname, $flds, $tableoptions=array()) 
     563        { 
     564                list($lines,$pkey,$idxs) = $this->_GenFields($flds, true); 
     565                // genfields can return FALSE at times 
     566                if ($lines == null) $lines = array(); 
    378567                 
    379568                $taboptions = $this->_Options($tableoptions); 
     
    381570                $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions); 
    382571                 
     572                // ggiunta - 2006/10/12 - KLUDGE: 
     573        // if we are on autoincrement, and table options includes REPLACE, the 
     574        // autoincrement sequence has already been dropped on table creation sql, so 
     575        // we avoid passing REPLACE to trigger creation code. This prevents 
     576        // creating sql that double-drops the sequence 
     577        if ($this->autoIncrement && isset($taboptions['REPLACE'])) 
     578                unset($taboptions['REPLACE']); 
    383579                $tsql = $this->_Triggers($tabname,$taboptions); 
    384580                foreach($tsql as $s) $sql[] = $s; 
    385581                 
     582                if (is_array($idxs)) { 
     583                        foreach($idxs as $idx => $idxdef) { 
     584                                $sql_idxs = $this->CreateIndexSql($idx, $tabname,  $idxdef['cols'], $idxdef['opts']); 
     585                                $sql = array_merge($sql, $sql_idxs); 
     586                        } 
     587                } 
     588 
    386589                return $sql; 
    387590        } 
    388591         
    389         function _GenFields($flds) 
     592        function _GenFields($flds,$widespacing=false) 
    390593        { 
    391594                if (is_string($flds)) { 
     
    399602                                foreach($f0 as $token) { 
    400603                                        switch (strtoupper($token)) { 
     604                                        case 'INDEX': 
     605                                                $f1['INDEX'] = ''; 
     606                                                // fall through intentionally 
    401607                                        case 'CONSTRAINT': 
    402608                                        case 'DEFAULT':  
     
    410616                                        } 
    411617                                } 
     618                                // 'index' token without a name means single column index: name it after column 
     619                                if (array_key_exists('INDEX', $f1) && $f1['INDEX'] == '') { 
     620                                        $f1['INDEX'] = isset($f0['NAME']) ? $f0['NAME'] : $f0[0]; 
     621                                        // check if column name used to create an index name was quoted 
     622                                        if (($f1['INDEX'][0] == '"' || $f1['INDEX'][0] == "'" || $f1['INDEX'][0] == "`") && 
     623                                                ($f1['INDEX'][0] == substr($f1['INDEX'], -1))) { 
     624                                                $f1['INDEX'] = $f1['INDEX'][0].'idx_'.substr($f1['INDEX'], 1, -1).$f1['INDEX'][0]; 
     625                                        } 
     626                                        else 
     627                                                $f1['INDEX'] = 'idx_'.$f1['INDEX']; 
     628                                } 
     629                                // reset it, so we don't get next field 1st token as INDEX... 
     630                                $hasparam = false; 
     631 
    412632                                $flds[] = $f1; 
    413633                                 
     
    417637                $lines = array(); 
    418638                $pkey = array(); 
     639                $idxs = array(); 
    419640                foreach($flds as $fld) { 
    420641                        $fld = _array_change_key_case($fld); 
    421                  
     642                         
    422643                        $fname = false; 
    423644                        $fdefault = false; 
     
    433654                        $fnotnull = false; 
    434655                        $funsigned = false; 
     656                        $findex = ''; 
     657                        $funiqueindex = false; 
    435658                         
    436659                        //----------------- 
     
    458681                                case 'AUTO':    $fautoinc = true; $fnotnull = true; break; 
    459682                                case 'KEY': 
    460                                 case 'PRIMARY': $fprimary = $v; $fnotnull = true; break; 
     683                // a primary key col can be non unique in itself (if key spans many cols...) 
     684                                case 'PRIMARY': $fprimary = $v; $fnotnull = true; /*$funiqueindex = true;*/ break; 
    461685                                case 'DEF': 
    462686                                case 'DEFAULT': $fdefault = $v; break; 
     
    466690                                case 'DEFTIMESTAMP': $fdefts = $v; break; 
    467691                                case 'CONSTRAINT': $fconstraint = $v; break; 
     692                                // let INDEX keyword create a 'very standard' index on column 
     693                                case 'INDEX': $findex = $v; break; 
     694                                case 'UNIQUE': $funiqueindex = true; break; 
    468695                                } //switch 
    469696                        } // foreach $fld 
     
    495722                        if ($ty == 'X') $fdefault = false; 
    496723                         
     724                        // build list of indexes 
     725                        if ($findex != '') { 
     726                                if (array_key_exists($findex, $idxs)) { 
     727                                        $idxs[$findex]['cols'][] = ($fname); 
     728                                        if (in_array('UNIQUE', $idxs[$findex]['opts']) != $funiqueindex) { 
     729                                                if ($this->debug) ADOConnection::outp("Index $findex defined once UNIQUE and once not"); 
     730                                        } 
     731                                        if ($funiqueindex && !in_array('UNIQUE', $idxs[$findex]['opts'])) 
     732                                                $idxs[$findex]['opts'][] = 'UNIQUE'; 
     733                                } 
     734                                else 
     735                                { 
     736                                        $idxs[$findex] = array(); 
     737                                        $idxs[$findex]['cols'] = array($fname); 
     738                                        if ($funiqueindex) 
     739                                                $idxs[$findex]['opts'] = array('UNIQUE'); 
     740                                        else 
     741                                                $idxs[$findex]['opts'] = array(); 
     742                                } 
     743                        } 
     744 
    497745                        //-------------------- 
    498746                        // CONSTRUCT FIELD SQL 
     
    509757                                        $fdefault = $this->connection->sysDate; 
    510758                                } 
    511                         } else if (strlen($fdefault) && !$fnoquote) 
     759                        } else if ($fdefault !== false && !$fnoquote) { 
    512760                                if ($ty == 'C' or $ty == 'X' or  
    513                                         ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) 
     761                                        ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) { 
     762 
     763                                        if (($ty == 'D' || $ty == 'T') && strtolower($fdefault) != 'null') { 
     764                                                // convert default date into database-aware code 
     765                                                if ($ty == 'T') 
     766                                                { 
     767                                                        $fdefault = $this->connection->DBTimeStamp($fdefault); 
     768                                                } 
     769                                                else 
     770                                                { 
     771                                                        $fdefault = $this->connection->DBDate($fdefault); 
     772                                                } 
     773                                        } 
     774                                        else 
    514775                                        if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ')  
    515776                                                $fdefault = trim($fdefault); 
    516777                                        else if (strtolower($fdefault) != 'null') 
    517778                                                $fdefault = $this->connection->qstr($fdefault); 
     779                                } 
     780                        } 
    518781                        $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned); 
    519782                         
    520                         $fname = str_pad($fname,16); 
     783                        // add index creation 
     784                        if ($widespacing) $fname = str_pad($fname,24); 
     785                         
     786                         // check for field names appearing twice 
     787            if (array_key_exists($fid, $lines)) { 
     788                 ADOConnection::outp("Field '$fname' defined twice"); 
     789            } 
     790                         
    521791                        $lines[$fid] = $fname.' '.$ftype.$suffix; 
    522792                         
     
    524794                } // foreach $flds 
    525795                 
    526                 return array($lines,$pkey); 
    527         } 
    528         /* 
     796                return array($lines,$pkey,$idxs); 
     797        } 
     798 
     799        /** 
    529800                 GENERATE THE SIZE PART OF THE DATATYPE 
    530801                        $ftype is the actual type 
     
    619890        } 
    620891         
    621         /* 
     892        /** 
    622893                GENERATE TRIGGERS IF NEEDED 
    623894                used when table has auto-incrementing field that is emulated using triggers 
     
    628899        } 
    629900         
    630         /* 
     901        /** 
    631902                Sanitize options, so that array elements with no keys are promoted to keys 
    632903        */ 
     
    642913        } 
    643914         
    644         /* 
    645         "Florian Buzin [ easywe ]" <florian.buzin@easywe.de> 
     915        /** 
     916        "Florian Buzin [ easywe ]" <florian.buzin#easywe.de> 
    646917         
    647918        This function changes/adds new fields to your table. You don't 
     
    650921        function ChangeTableSQL($tablename, $flds, $tableoptions = false) 
    651922        { 
     923        global $ADODB_FETCH_MODE; 
     924         
     925                $save = $ADODB_FETCH_MODE; 
     926                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 
     927                if ($this->connection->fetchMode !== false) $savem = $this->connection->SetFetchMode(false); 
     928                 
    652929                // check table exists 
    653                 $cols = &$this->MetaColumns($tablename); 
     930                $save_handler = $this->connection->raiseErrorFn; 
     931                $this->connection->raiseErrorFn = ''; 
     932                $cols = $this->MetaColumns($tablename); 
     933                $this->connection->raiseErrorFn = $save_handler; 
     934                 
     935                if (isset($savem)) $this->connection->SetFetchMode($savem); 
     936                $ADODB_FETCH_MODE = $save; 
     937                 
    654938                if ( empty($cols)) {  
    655939                        return $this->CreateTableSQL($tablename, $flds, $tableoptions); 
    656940                } 
    657941                 
     942                if (is_array($flds)) { 
     943                // Cycle through the update fields, comparing 
     944                // existing fields to fields to update. 
     945                // if the Metatype and size is exactly the 
     946                // same, ignore - by Mark Newham 
     947                        $holdflds = array(); 
     948                        foreach($flds as $k=>$v) { 
     949                                if ( isset($cols[$k]) && is_object($cols[$k]) ) { 
     950                                        // If already not allowing nulls, then don't change 
     951                                        $obj = $cols[$k]; 
     952                                        if (isset($obj->not_null) && $obj->not_null) 
     953                                                $v = str_replace('NOT NULL','',$v); 
     954 
     955                                        $c = $cols[$k]; 
     956                                        $ml = $c->max_length; 
     957                                        $mt = $this->MetaType($c->type,$ml); 
     958                                        if ($ml == -1) $ml = ''; 
     959                                        if ($mt == 'X') $ml = $v['SIZE']; 
     960                                        if (($mt != $v['TYPE']) ||  $ml != $v['SIZE']) { 
     961                                                $holdflds[$k] = $v; 
     962                                        } 
     963                                } else { 
     964                                        $holdflds[$k] = $v; 
     965                                }                
     966                        } 
     967                        $flds = $holdflds; 
     968                } 
     969         
     970 
    658971                // already exists, alter table instead 
    659                 list($lines,$pkey) = $this->_GenFields($flds); 
     972                list($lines,$pkey,$idxs) = $this->_GenFields($flds); 
     973                // genfields can return FALSE at times 
     974                if ($lines == null) $lines = array(); 
    660975                $alter = 'ALTER TABLE ' . $this->TableName($tablename); 
    661976                $sql = array(); 
    662                  
     977 
    663978                foreach ( $lines as $id => $v ) { 
    664979                        if ( isset($cols[$id]) && is_object($cols[$id]) ) { 
     980                         
     981                                $flds = Lens_ParseArgs($v,','); 
     982                                 
     983                                //  We are trying to change the size of the field, if not allowed, simply ignore the request. 
     984                                if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) { 
     985                                        echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>"; 
     986                                        continue;         
     987                                } 
    665988                                $sql[] = $alter . $this->alterCol . ' ' . $v; 
    666989                        } else { 
Note: See TracChangeset for help on using the changeset viewer.