Changeset 6216


Ignore:
Timestamp:
May 17, 2010, 10:58:24 PM (14 years ago)
Author:
patdenice
Message:

mysqldump class now take into account null fields

Location:
extensions/autoupdate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/autoupdate/branches/1.7/include/mysqldump.php

    r6205 r6216  
    145145                while ( $record = mysql_fetch_assoc($records) ) {
    146146                        $structure .= '`'.$record['Field'].'` '.$record['Type'];
    147                         if ( !empty($record['Default']) )
     147                        if ( isset($record['Default']) )
    148148                                $structure .= ' DEFAULT \''.$record['Default'].'\'';
    149149                        if ( @strcmp($record['Null'],'YES') != 0 )
    150150                                $structure .= ' NOT NULL';
     151                        elseif ( is_null($record['Default']) )
     152                                $structure .= ' DEFAULT NULL';
    151153                        if ( !empty($record['Extra']) )
    152154                                $structure .= ' '.$record['Extra'];
     
    206208                        $selectStatement .= ", ";
    207209                }
    208                 $insertStatement = @substr($insertStatement,0,-2).') VALUES';
     210                $insertStatement = @substr($insertStatement,0,-2).') VALUES'."\n";
    209211                $selectStatement = @substr($selectStatement,0,-2).' FROM `'.$table.'`';
    210212
     
    222224                                        if ( @$hexField[$j] && (@strlen($record[$field_name]) > 0) )
    223225                                                $data .= "0x".$record[$field_name];
     226                                        elseif (is_null($record[$field_name]))
     227                                                $data .= "NULL";
    224228                                        else
    225229                                                $data .= "'".@str_replace('\"','"',@mysql_escape_string($record[$field_name]))."'";
  • extensions/autoupdate/trunk/include/mysqldump.php

    r6167 r6216  
    145145                while ( $record = mysql_fetch_assoc($records) ) {
    146146                        $structure .= '`'.$record['Field'].'` '.$record['Type'];
    147                         if ( !empty($record['Default']) )
     147                        if ( isset($record['Default']) )
    148148                                $structure .= ' DEFAULT \''.$record['Default'].'\'';
    149149                        if ( @strcmp($record['Null'],'YES') != 0 )
    150150                                $structure .= ' NOT NULL';
     151                        elseif ( is_null($record['Default']) )
     152                                $structure .= ' DEFAULT NULL';
    151153                        if ( !empty($record['Extra']) )
    152154                                $structure .= ' '.$record['Extra'];
     
    206208                        $selectStatement .= ", ";
    207209                }
    208                 $insertStatement = @substr($insertStatement,0,-2).') VALUES';
     210                $insertStatement = @substr($insertStatement,0,-2).') VALUES'."\n";
    209211                $selectStatement = @substr($selectStatement,0,-2).' FROM `'.$table.'`';
    210212
     
    222224                                        if ( @$hexField[$j] && (@strlen($record[$field_name]) > 0) )
    223225                                                $data .= "0x".$record[$field_name];
     226                                        elseif (is_null($record[$field_name]))
     227                                                $data .= "NULL";
    224228                                        else
    225                                                 $data .= "'".@str_replace('\"','"',@mysql_escape_string($record[$field_name]))."'";
     229                                                $data .= "'".@str_replace('\"','"',@mysql_real_escape_string($record[$field_name]))."'";
    226230                                        $data .= ',';
    227231                                }
Note: See TracChangeset for help on using the changeset viewer.