Changeset 2845

Show
Ignore:
Timestamp:
07/28/08 00:55:45 (4 months ago)
Author:
fumiakiy
Message:

Modified how to generate SQL to update meta to the new structure, mainly for Enterprise drivers. BugId:80791, BugId:80733

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-42/lib/MT/Upgrade.pm

    r2775 r2845  
    11481148    my $dbh = $driver->rw_handle; 
    11491149    my $dbd = $driver->dbd; 
    1150     my $stmt = $dbd->sql_class->new; 
    11511150 
    11521151    my $meta_col = $param{meta_column} || 'meta'; 
     
    11561155    return 0 unless $db_defs && exists($db_defs->{$meta_col}); 
    11571156 
    1158     my $id_col = $dbd->db_column_name($class->datasource, 'id'); 
    1159     $meta_col = $dbd->db_column_name($class->datasource, $meta_col); 
    1160     $stmt->add_where( $meta_col => { not_null => 1 } ); 
    1161     $stmt->limit( 101 ); 
    1162  
    1163     my $sql = join ' ', 'SELECT', $meta_col, ',', $id_col, 'FROM', 
    1164         $driver->table_for($class), 
    1165         $stmt->as_sql_where(), 
    1166         $stmt->as_limit; 
    1167  
     1157    my $terms = { 
     1158        $meta_col => { not_null => 1 } 
     1159    }; 
     1160    my $args = { 
     1161        'limit'      => 101, 
     1162        'fetchonly' => [ 'id' ],  # meta is added to the select list separately 
     1163        $offset ? ( 'offset' => $offset ) : () 
     1164    }; 
     1165    my $stmt = $driver->prepare_statement( $class, $terms, $args ); 
     1166    my $db_meta_col = $dbd->db_column_name($class->datasource, $meta_col); 
     1167    ## Meta column has to be added in here because it's already 
     1168    ## gone from the column_names - something fetchonly relies on 
     1169    $stmt->add_select( $db_meta_col => $db_meta_col ); 
     1170    my $sql = $stmt->as_sql; 
    11681171    my $sth = $dbh->prepare($sql); 
    11691172    return 0 if !$sth; # ignore this operation if _meta column doesn't exist 
     
    11911194    while (my $row = $sth->fetchrow_arrayref) { 
    11921195        $rows++; 
    1193         my ($rawmeta, $id) = @$row; 
     1196        my ($id, $rawmeta) = @$row;  ## add_select pushes the column - it should be in this order 
    11941197        if (defined $rawmeta) { 
    11951198            push @ids, $id; 
     
    12471250    # now, clear the meta column for each of the objects touched 
    12481251    if (@ids) { 
     1252        my $id_col = $dbd->db_column_name($class->datasource, 'id'); 
    12491253        my $list = join ",", @ids; 
    12501254        my $sql = join " ", "UPDATE", $driver->table_for($class), 
    1251             "SET", $meta_col, "=NULL WHERE", $id_col, " IN ($list)"; 
     1255            "SET", $db_meta_col, "=NULL WHERE", $id_col, " IN ($list)"; 
    12521256        $dbh->do($sql); 
    12531257    } 
     
    12611265            # to get dropped as the table is updated for other 
    12621266            # new columns anyway. 
    1263             $sql = $dbd->ddl_class->drop_column_sql($class, 
    1264                 $param{meta_column} || 'meta'); 
     1267            $sql = $dbd->ddl_class->drop_column_sql($class, $meta_col); 
    12651268            $self->add_step('core_drop_meta_for_table', class => $db_class, sql => $sql); 
    12661269        } 
     
    12801283    my $driver = $class->dbi_driver; 
    12811284    my $dbh = $driver->rw_handle; 
    1282     $dbh->do($sql); 
     1285    my $err; 
     1286    eval { 
     1287        $dbh->do($sql) or $err = $dbh->errstr; 
     1288    }; 
     1289    # ignore drop errors; the column has probably been 
     1290    # removed already 
     1291    #if ($err) { 
     1292    #    print STDERR "$err: $sql\n"; 
     1293    #} 
    12831294 
    12841295    return 0;