@@ -253,6 +253,14 @@ public function testSelectFromDual() {
253253 $ this ->assertEquals ( 1 , $ result [0 ]->output );
254254 }
255255
256+ public function testShowCreateTableNotFound () {
257+ $ this ->assertQuery (
258+ 'SHOW CREATE TABLE _no_such_table; '
259+ );
260+ $ results = $ this ->engine ->get_query_results ();
261+ $ this ->assertCount ( 0 , $ results );
262+ }
263+
256264 public function testShowCreateTable1 () {
257265 $ this ->assertQuery (
258266 "CREATE TABLE _tmp_table (
@@ -270,12 +278,42 @@ public function testShowCreateTable1() {
270278 $ results = $ this ->engine ->get_query_results ();
271279 # TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
272280 $ this ->assertEquals (
281+ "CREATE TABLE `_tmp_table` (
282+ `ID` bigint NOT NULL AUTO_INCREMENT,
283+ `option_name` varchar(255) DEFAULT '',
284+ `option_value` text NOT NULL DEFAULT '',
285+ PRIMARY KEY (`ID`),
286+ KEY `composite` (`option_name`, `option_value`),
287+ UNIQUE KEY `option_name` (`option_name`)
288+ ); " ,
289+ $ results [0 ]->{'Create Table ' }
290+ );
291+ }
292+
293+ public function testShowCreateTableQuoted () {
294+ $ this ->assertQuery (
273295 "CREATE TABLE _tmp_table (
274- `ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
296+ ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
297+ option_name VARCHAR(255) default '',
298+ option_value TEXT NOT NULL,
299+ UNIQUE KEY option_name (option_name),
300+ KEY composite (option_name, option_value)
301+ ); "
302+ );
303+
304+ $ this ->assertQuery (
305+ 'SHOW CREATE TABLE `_tmp_table`; '
306+ );
307+ $ results = $ this ->engine ->get_query_results ();
308+ # TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
309+ $ this ->assertEquals (
310+ "CREATE TABLE `_tmp_table` (
311+ `ID` bigint NOT NULL AUTO_INCREMENT,
275312 `option_name` varchar(255) DEFAULT '',
276313 `option_value` text NOT NULL DEFAULT '',
277- KEY _tmp_table__composite (option_name, option_value),
278- UNIQUE KEY _tmp_table__option_name (option_name)
314+ PRIMARY KEY (`ID`),
315+ KEY `composite` (`option_name`, `option_value`),
316+ UNIQUE KEY `option_name` (`option_name`)
279317); " ,
280318 $ results [0 ]->{'Create Table ' }
281319 );
@@ -293,8 +331,8 @@ public function testShowCreateTableSimpleTable() {
293331 );
294332 $ results = $ this ->engine ->get_query_results ();
295333 $ this ->assertEquals (
296- 'CREATE TABLE _tmp_table (
297- `ID` bigint NOT NULL
334+ 'CREATE TABLE ` _tmp_table` (
335+ `ID` bigint NOT NULL DEFAULT 0
298336); ' ,
299337 $ results [0 ]->{'Create Table ' }
300338 );
@@ -322,16 +360,103 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
322360 );
323361 $ results = $ this ->engine ->get_query_results ();
324362 $ this ->assertEquals (
325- 'CREATE TABLE _tmp_table (
326- `ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
363+ 'CREATE TABLE ` _tmp_table` (
364+ `ID` bigint NOT NULL AUTO_INCREMENT ,
327365 `option_name` smallint NOT NULL DEFAULT 14,
328366 `option_value` text NOT NULL DEFAULT \'\',
329- KEY _tmp_table__option_name (option_name)
367+ PRIMARY KEY (`ID`),
368+ KEY `option_name` (`option_name`)
330369); ' ,
331370 $ results [0 ]->{'Create Table ' }
332371 );
333372 }
334373
374+ public function testCreateTablseWithIdenticalIndexNames () {
375+ $ this ->assertQuery (
376+ "CREATE TABLE _tmp_table_a (
377+ ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
378+ option_name VARCHAR(255) default '',
379+ option_value TEXT NOT NULL,
380+ KEY `option_name` (`option_name`),
381+ KEY `double__underscores` (`option_name`, `ID`)
382+ ); "
383+ );
384+
385+ $ this ->assertQuery (
386+ "CREATE TABLE _tmp_table_b (
387+ ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
388+ option_name VARCHAR(255) default '',
389+ option_value TEXT NOT NULL,
390+ KEY `option_name` (`option_name`),
391+ KEY `double__underscores` (`option_name`, `ID`)
392+ ); "
393+ );
394+ }
395+
396+ public function testShowCreateTablePreservesDoubleUnderscoreKeyNames () {
397+ $ this ->assertQuery (
398+ "CREATE TABLE _tmp__table (
399+ ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
400+ option_name VARCHAR(255) default '',
401+ option_value TEXT NOT NULL,
402+ KEY `option_name` (`option_name`),
403+ KEY `double__underscores` (`option_name`, `ID`)
404+ ); "
405+ );
406+
407+ $ this ->assertQuery (
408+ 'SHOW CREATE TABLE _tmp__table; '
409+ );
410+ $ results = $ this ->engine ->get_query_results ();
411+ $ this ->assertEquals (
412+ 'CREATE TABLE `_tmp__table` (
413+ `ID` bigint NOT NULL AUTO_INCREMENT,
414+ `option_name` varchar(255) DEFAULT \'\',
415+ `option_value` text NOT NULL DEFAULT \'\',
416+ PRIMARY KEY (`ID`),
417+ KEY `double__underscores` (`option_name`, `ID`),
418+ KEY `option_name` (`option_name`)
419+ ); ' ,
420+ $ results [0 ]->{'Create Table ' }
421+ );
422+ }
423+
424+ public function testShowCreateTableWithPrimaryKeyColumnsReverseOrdered () {
425+ $ this ->assertQuery (
426+ 'CREATE TABLE `_tmp_table` (
427+ `ID_A` BIGINT NOT NULL,
428+ `ID_B` BIGINT NOT NULL,
429+ `ID_C` BIGINT NOT NULL,
430+ PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
431+ ); '
432+ );
433+
434+ $ this ->assertQuery (
435+ 'SHOW CREATE TABLE _tmp_table; '
436+ );
437+ $ results = $ this ->engine ->get_query_results ();
438+ $ this ->assertEquals (
439+ 'CREATE TABLE `_tmp_table` (
440+ `ID_A` bigint NOT NULL DEFAULT 0,
441+ `ID_B` bigint NOT NULL DEFAULT 0,
442+ `ID_C` bigint NOT NULL DEFAULT 0,
443+ PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
444+ ); ' ,
445+ $ results [0 ]->{'Create Table ' }
446+ );
447+ }
448+
449+ public function testShowCreateTableWithColumnKeys () {
450+ $ this ->assertQuery (
451+ "CREATE TABLE _tmp_table (
452+ `ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
453+ `option_name` varchar(255) DEFAULT '',
454+ `option_value` text NOT NULL DEFAULT '',
455+ KEY _tmp_table__composite (option_name, option_value),
456+ UNIQUE KEY _tmp_table__option_name (option_name) ); "
457+ );
458+ }
459+
335460 public function testSelectIndexHintForce () {
336461 $ this ->assertQuery ( "INSERT INTO _options (option_name) VALUES ('first'); " );
337462 $ result = $ this ->assertQuery (
@@ -668,6 +793,60 @@ public function testCreateTableSpatialIndex() {
668793 $ this ->assertEquals ( 1 , $ result );
669794 }
670795
796+ public function testCreateTableWithMultiValueColumnTypeModifiers () {
797+ $ result = $ this ->assertQuery (
798+ "CREATE TABLE wptests_users (
799+ ID bigint(20) unsigned NOT NULL auto_increment,
800+ decimal_column DECIMAL(10,2) NOT NULL DEFAULT 0,
801+ float_column FLOAT(10,2) NOT NULL DEFAULT 0,
802+ enum_column ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a',
803+ PRIMARY KEY (ID),
804+ ) "
805+ );
806+ $ this ->assertEquals ( '' , $ this ->engine ->get_error_message () );
807+ $ this ->assertEquals ( 1 , $ result );
808+
809+ $ this ->assertQuery ( 'DESCRIBE wptests_users; ' );
810+ $ results = $ this ->engine ->get_query_results ();
811+ $ this ->assertEquals (
812+ array (
813+ (object ) array (
814+ 'Field ' => 'ID ' ,
815+ 'Type ' => 'bigint(20) unsigned ' ,
816+ 'Null ' => 'NO ' ,
817+ 'Key ' => 'PRI ' ,
818+ 'Default ' => '0 ' ,
819+ 'Extra ' => '' ,
820+ ),
821+ (object ) array (
822+ 'Field ' => 'decimal_column ' ,
823+ 'Type ' => 'decimal(10,2) ' ,
824+ 'Null ' => 'NO ' ,
825+ 'Key ' => '' ,
826+ 'Default ' => 0 ,
827+ 'Extra ' => '' ,
828+ ),
829+ (object ) array (
830+ 'Field ' => 'float_column ' ,
831+ 'Type ' => 'float(10,2) ' ,
832+ 'Null ' => 'NO ' ,
833+ 'Key ' => '' ,
834+ 'Default ' => 0 ,
835+ 'Extra ' => '' ,
836+ ),
837+ (object ) array (
838+ 'Field ' => 'enum_column ' ,
839+ 'Type ' => "enum('a','b','c') " ,
840+ 'Null ' => 'NO ' ,
841+ 'Key ' => '' ,
842+ 'Default ' => 'a ' ,
843+ 'Extra ' => '' ,
844+ ),
845+ ),
846+ $ results
847+ );
848+ }
849+
671850 public function testAlterTableAddColumn () {
672851 $ result = $ this ->assertQuery (
673852 "CREATE TABLE _tmp_table (
0 commit comments