Ignore:
Timestamp:
09/26/13 15:41:49 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php

    r34 r8222  
    22 
    33/** 
    4   V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 
     4  V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 
    55  Released under both BSD license and Lesser GPL library license.  
    66  Whenever there is any discrepancy between the two licenses,  
     
    3131                        $len = $fieldobj->max_length; 
    3232                } 
    33                 $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->unique &&  
    34                         $fieldobj->has_default && substr($fieldobj->default_value,0,8) == 'nextval('; 
     33                $is_serial = is_object($fieldobj) && !empty($fieldobj->primary_key) && !empty($fieldobj->unique) &&  
     34                        !empty($fieldobj->has_default) && substr($fieldobj->default_value,0,8) == 'nextval('; 
    3535                 
    3636                switch (strtoupper($t)) { 
     
    101101                         
    102102                case 'D': return 'DATE'; 
     103                case 'TS': 
    103104                case 'T': return 'TIMESTAMP'; 
    104105                 
     
    130131                $tabname = $this->TableName ($tabname); 
    131132                $sql = array(); 
     133                $not_null = false; 
    132134                list($lines,$pkey) = $this->_GenFields($flds); 
    133135                $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; 
     
    136138                                $v = preg_replace('/NOT NULL/i','',$v); 
    137139                        } 
    138                         if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/',$v,$matches)) { 
     140                        if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) { 
    139141                                list(,$colname,$default) = $matches; 
    140142                                $sql[] = $alter . str_replace('DEFAULT '.$default,'',$v); 
     
    151153                return $sql; 
    152154        } 
     155 
     156 
     157        function DropIndexSQL ($idxname, $tabname = NULL) 
     158        { 
     159           return array(sprintf($this->dropIndex, $this->TableName($idxname), $this->TableName($tabname))); 
     160        } 
    153161         
    154162        /** 
     
    163171         * @return array with SQL strings 
    164172         */ 
     173         /* 
    165174        function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') 
    166175        { 
     
    170179                } 
    171180                return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions); 
     181        }*/ 
     182         
     183        function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') 
     184        { 
     185           // Check if alter single column datatype available - works with 8.0+ 
     186           $has_alter_column = 8.0 <= (float) @$this->serverInfo['version']; 
     187         
     188           if ($has_alter_column) { 
     189              $tabname = $this->TableName($tabname); 
     190              $sql = array(); 
     191              list($lines,$pkey) = $this->_GenFields($flds); 
     192                  $set_null = false; 
     193              $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; 
     194              foreach($lines as $v) { 
     195                if ($not_null = preg_match('/NOT NULL/i',$v)) { 
     196                    $v = preg_replace('/NOT NULL/i','',$v); 
     197                } 
     198                 // this next block doesn't work - there is no way that I can see to  
     199                 // explicitly ask a column to be null using $flds 
     200                else if ($set_null = preg_match('/NULL/i',$v)) { 
     201                    // if they didn't specify not null, see if they explicitely asked for null 
     202                    $v = preg_replace('/\sNULL/i','',$v); 
     203                } 
     204                  
     205                        if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) { 
     206                                $existing = $this->MetaColumns($tabname); 
     207                                list(,$colname,$default) = $matches; 
     208                                if ($this->connection) $old_coltype = $this->connection->MetaType($existing[strtoupper($colname)]); 
     209                                else $old_coltype = $t; 
     210                                $v = preg_replace('/^' . preg_quote($colname) . '\s/', '', $v); 
     211                                $t = trim(str_replace('DEFAULT '.$default,'',$v)); 
     212 
     213                                // Type change from bool to int 
     214                                if ( $old_coltype == 'L' && $t == 'INTEGER' ) { 
     215                                        $sql[] = $alter . $colname . ' DROP DEFAULT'; 
     216                                        $sql[] = $alter . $colname . " TYPE $t USING ($colname::BOOL)::INT"; 
     217                                        $sql[] = $alter . $colname . " SET DEFAULT $default"; 
     218                                } 
     219                                // Type change from int to bool 
     220                                else if ( $old_coltype == 'I' && $t == 'BOOLEAN' ) { 
     221                                        $sql[] = $alter . $colname . ' DROP DEFAULT'; 
     222                                        $sql[] = $alter . $colname . " TYPE $t USING CASE WHEN $colname = 0 THEN false ELSE true END"; 
     223                                        $sql[] = $alter . $colname . " SET DEFAULT " . $this->connection->qstr($default); 
     224                                } 
     225                                // Any other column types conversion 
     226                                else { 
     227                                        $sql[] = $alter . $colname . " TYPE $t"; 
     228                                        $sql[] = $alter . $colname . " SET DEFAULT $default"; 
     229                                } 
     230                          
     231                          
     232                 }  
     233                 else { 
     234                    // drop default? 
     235                    preg_match ('/^\s*(\S+)\s+(.*)$/',$v,$matches); 
     236                    list (,$colname,$rest) = $matches; 
     237                    $sql[] = $alter . $colname . ' TYPE ' . $rest; 
     238                 } 
     239         
     240#                list($colname) = explode(' ',$v); 
     241                 if ($not_null) { 
     242                    // this does not error out if the column is already not null 
     243                                $sql[] = $alter . $colname . ' SET NOT NULL'; 
     244                 } 
     245                 if ($set_null) { 
     246                    // this does not error out if the column is already null 
     247                    $sql[] = $alter . $colname . ' DROP NOT NULL'; 
     248                 } 
     249              } 
     250              return $sql; 
     251           } 
     252         
     253           // does not have alter column 
     254           if (!$tableflds) { 
     255              if ($this->debug) ADOConnection::outp("AlterColumnSQL needs a complete table-definiton for PostgreSQL"); 
     256              return array(); 
     257           } 
     258           return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions); 
    172259        } 
    173260         
     
    265352 
    266353        // return string must begin with space 
    267         function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint) 
     354        function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) 
    268355        { 
    269356                if ($fautoinc) { 
     
    292379                } 
    293380                return "DROP SEQUENCE ".$seq; 
     381        } 
     382         
     383        function RenameTableSQL($tabname,$newname) 
     384        { 
     385                if (!empty($this->schema)) { 
     386                        $rename_from = $this->TableName($tabname); 
     387                        $schema_save = $this->schema; 
     388                        $this->schema = false; 
     389                        $rename_to = $this->TableName($newname); 
     390                        $this->schema = $schema_save; 
     391                        return array (sprintf($this->renameTable, $rename_from, $rename_to)); 
     392                } 
     393 
     394                return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); 
    294395        } 
    295396         
Note: See TracChangeset for help on using the changeset viewer.