Changeset 2845
- Timestamp:
- 07/28/08 00:55:45 (4 months ago)
- Files:
-
- branches/release-42/lib/MT/Upgrade.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-42/lib/MT/Upgrade.pm
r2775 r2845 1148 1148 my $dbh = $driver->rw_handle; 1149 1149 my $dbd = $driver->dbd; 1150 my $stmt = $dbd->sql_class->new;1151 1150 1152 1151 my $meta_col = $param{meta_column} || 'meta'; … … 1156 1155 return 0 unless $db_defs && exists($db_defs->{$meta_col}); 1157 1156 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; 1168 1171 my $sth = $dbh->prepare($sql); 1169 1172 return 0 if !$sth; # ignore this operation if _meta column doesn't exist … … 1191 1194 while (my $row = $sth->fetchrow_arrayref) { 1192 1195 $rows++; 1193 my ($ rawmeta, $id) = @$row;1196 my ($id, $rawmeta) = @$row; ## add_select pushes the column - it should be in this order 1194 1197 if (defined $rawmeta) { 1195 1198 push @ids, $id; … … 1247 1250 # now, clear the meta column for each of the objects touched 1248 1251 if (@ids) { 1252 my $id_col = $dbd->db_column_name($class->datasource, 'id'); 1249 1253 my $list = join ",", @ids; 1250 1254 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)"; 1252 1256 $dbh->do($sql); 1253 1257 } … … 1261 1265 # to get dropped as the table is updated for other 1262 1266 # 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); 1265 1268 $self->add_step('core_drop_meta_for_table', class => $db_class, sql => $sql); 1266 1269 } … … 1280 1283 my $driver = $class->dbi_driver; 1281 1284 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 #} 1283 1294 1284 1295 return 0;
