@@ -457,6 +457,30 @@ public function testShowCreateTableWithColumnKeys() {
457
457
);
458
458
}
459
459
460
+ public function testShowCreateTableWithCorrectDefaultValues () {
461
+ $ this ->assertQuery (
462
+ "CREATE TABLE _tmp__table (
463
+ ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
464
+ default_empty_string VARCHAR(255) default '',
465
+ null_no_default VARCHAR(255),
466
+ ); "
467
+ );
468
+
469
+ $ this ->assertQuery (
470
+ 'SHOW CREATE TABLE _tmp__table; '
471
+ );
472
+ $ results = $ this ->engine ->get_query_results ();
473
+ $ this ->assertEquals (
474
+ 'CREATE TABLE `_tmp__table` (
475
+ `ID` bigint NOT NULL AUTO_INCREMENT,
476
+ `default_empty_string` varchar(255) DEFAULT \'\',
477
+ `null_no_default` varchar(255),
478
+ PRIMARY KEY (`ID`)
479
+ ); ' ,
480
+ $ results [0 ]->{'Create Table ' }
481
+ );
482
+ }
483
+
460
484
public function testSelectIndexHintForce () {
461
485
$ this ->assertQuery ( "INSERT INTO _options (option_name) VALUES ('first'); " );
462
486
$ result = $ this ->assertQuery (
@@ -1074,6 +1098,57 @@ public function testAlterTableModifyColumn() {
1074
1098
$ this ->assertEquals ( 2 , $ result [0 ]->ID );
1075
1099
}
1076
1100
1101
+
1102
+ public function testAlterTableModifyColumnWithSkippedColumnKeyword () {
1103
+ $ this ->assertQuery (
1104
+ "CREATE TABLE _tmp_table (
1105
+ ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
1106
+ name varchar(20) NOT NULL default '',
1107
+ lastname varchar(20) NOT NULL default '',
1108
+ KEY composite (name, lastname),
1109
+ UNIQUE KEY name (name)
1110
+ ); "
1111
+ );
1112
+ // Insert a record
1113
+ $ result = $ this ->assertQuery ( "INSERT INTO _tmp_table (ID, name, lastname) VALUES (1, 'Johnny', 'Appleseed'); " );
1114
+ $ this ->assertEquals ( 1 , $ result );
1115
+
1116
+ // Primary key violation:
1117
+ $ result = $ this ->engine ->query ( "INSERT INTO _tmp_table (ID, name, lastname) VALUES (1, 'Mike', 'Pearseed'); " );
1118
+ $ this ->assertEquals ( false , $ result );
1119
+
1120
+ // Unique constraint violation:
1121
+ $ result = $ this ->engine ->query ( "INSERT INTO _tmp_table (ID, name, lastname) VALUES (2, 'Johnny', 'Appleseed'); " );
1122
+ $ this ->assertEquals ( false , $ result );
1123
+
1124
+ // Rename the "name" field to "firstname":
1125
+ $ result = $ this ->engine ->query ( "ALTER TABLE _tmp_table CHANGE name firstname varchar(50) NOT NULL default 'mark'; " );
1126
+ $ this ->assertEquals ( '' , $ this ->engine ->get_error_message () );
1127
+ $ this ->assertEquals ( 1 , $ result );
1128
+
1129
+ // Confirm the original data is still there:
1130
+ $ result = $ this ->engine ->query ( 'SELECT * FROM _tmp_table; ' );
1131
+ $ this ->assertCount ( 1 , $ result );
1132
+ $ this ->assertEquals ( 1 , $ result [0 ]->ID );
1133
+ $ this ->assertEquals ( 'Johnny ' , $ result [0 ]->firstname );
1134
+ $ this ->assertEquals ( 'Appleseed ' , $ result [0 ]->lastname );
1135
+
1136
+ // Confirm the primary key is intact:
1137
+ $ result = $ this ->engine ->query ( "INSERT INTO _tmp_table (ID, firstname, lastname) VALUES (1, 'Mike', 'Pearseed'); " );
1138
+ $ this ->assertEquals ( false , $ result );
1139
+
1140
+ // Confirm the unique key is intact:
1141
+ $ result = $ this ->engine ->query ( "INSERT INTO _tmp_table (ID, firstname, lastname) VALUES (2, 'Johnny', 'Appleseed'); " );
1142
+ $ this ->assertEquals ( false , $ result );
1143
+
1144
+ // Confirm the autoincrement still works:
1145
+ $ result = $ this ->engine ->query ( "INSERT INTO _tmp_table (firstname, lastname) VALUES ('John', 'Doe'); " );
1146
+ $ this ->assertEquals ( true , $ result );
1147
+ $ result = $ this ->engine ->query ( "SELECT * FROM _tmp_table WHERE firstname='John'; " );
1148
+ $ this ->assertCount ( 1 , $ result );
1149
+ $ this ->assertEquals ( 2 , $ result [0 ]->ID );
1150
+ }
1151
+
1077
1152
public function testAlterTableModifyColumnWithHyphens () {
1078
1153
$ result = $ this ->assertQuery (
1079
1154
'CREATE TABLE wptests_dbdelta_test2 (
0 commit comments