Ticket #20263: 20263.4.diff
| File 20263.4.diff, 3.9 KB (added by , 10 years ago) |
|---|
-
src/wp-admin/includes/upgrade.php
2201 2201 case 'unique': 2202 2202 case 'key': 2203 2203 $validfield = false; 2204 $indices[] = trim( trim($fld), ", \n");2204 $indices[] = trim( trim( $fld ), ", \n" ); 2205 2205 break; 2206 2206 } 2207 2207 $fld = trim( $fld ); … … 2242 2242 2243 2243 if ( $do_change ) { 2244 2244 // Add a query to change the column type. 2245 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field}" . $cfields[ $tablefield_field_lowercased ];2245 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; 2246 2246 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2247 2247 } 2248 2248 } … … 2252 2252 $default_value = $matches[1]; 2253 2253 if ($tablefield->Default != $default_value) { 2254 2254 // Add a query to change the column's default value 2255 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field}SET DEFAULT '{$default_value}'";2255 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'"; 2256 2256 $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; 2257 2257 } 2258 2258 } … … 2312 2312 if ($index_columns != '') $index_columns .= ','; 2313 2313 2314 2314 // Add the field to the column list string. 2315 $index_columns .= $column_data['fieldname'];2315 $index_columns .= '`' . $column_data['fieldname'] . '`'; 2316 2316 if ($column_data['subpart'] != '') { 2317 2317 $index_columns .= '('.$column_data['subpart'].')'; 2318 2318 } -
tests/phpunit/tests/dbdelta.php
488 488 489 489 $this->assertEmpty( $updates ); 490 490 } 491 492 /** 493 * @ticket 20263 494 */ 495 function test_query_with_backticks_does_not_cause_a_query_to_alter_all_columns_and_indices_to_run_even_if_none_have_changed() { 496 global $wpdb; 497 498 $schema = " 499 CREATE TABLE {$wpdb->prefix}dbdelta_test2 ( 500 `id` bigint(20) NOT NULL AUTO_INCREMENT, 501 `references` varchar(255) NOT NULL, 502 PRIMARY KEY (`id`), 503 KEY `compound_key` (`id`,`references`) 504 ) 505 "; 506 507 $wpdb->query( $schema ); 508 509 $updates = dbDelta( $schema ); 510 511 $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test2" ); 512 $compound_key_index = wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key' ) ); 513 514 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test2" ); 515 516 $this->assertCount( 2, $compound_key_index ); 517 $this->assertEmpty( $updates ); 518 } 519 520 /** 521 * @group 20263 522 */ 523 function test_query_with_reserved_keywords_does_not_explode() { 524 global $wpdb; 525 526 $updates = dbDelta( 527 " 528 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 529 id bigint(20) NOT NULL AUTO_INCREMENT, 530 column_1 varchar(255) NOT NULL, 531 column_2 text, 532 column_3 blob, 533 `references` varchar(255) NOT NULL, 534 PRIMARY KEY (id), 535 KEY key_1 (column_1), 536 KEY compound_key (id,column_1), 537 KEY compound_key2 (id,`references`) 538 FULLTEXT KEY fulltext_key (column_1) 539 ) ENGINE=MyISAM 540 " 541 ); 542 543 $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test" ); 544 545 $this->assertCount( 2, wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key2' ) , 'AND' ) ); 546 547 $this->assertSame( 548 array( 549 "{$wpdb->prefix}dbdelta_test.references" => "Added column {$wpdb->prefix}dbdelta_test.references", 550 0 => "Added index {$wpdb->prefix}dbdelta_test KEY compound_key2 (id,`references`)", 551 ), 552 $updates 553 ); 554 } 491 555 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)