DBZ-1833 - CREATE TABLE [IF NOT EXISTS] shouldn't update state for existing table
This commit is contained in:
parent
504648d367
commit
4e45347f8e
@ -44,8 +44,10 @@ public CreateTableParserListener(MySqlAntlrDdlParser parser, List<ParseTreeListe
|
||||
@Override
|
||||
public void enterColumnCreateTable(MySqlParser.ColumnCreateTableContext ctx) {
|
||||
TableId tableId = parser.parseQualifiedTableId(ctx.tableName().fullId());
|
||||
tableEditor = parser.databaseTables().editOrCreateTable(tableId);
|
||||
super.enterColumnCreateTable(ctx);
|
||||
if (parser.databaseTables().forTable(tableId) == null) {
|
||||
tableEditor = parser.databaseTables().editOrCreateTable(tableId);
|
||||
super.enterColumnCreateTable(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,6 +58,24 @@ public void beforeEach() {
|
||||
tables = new Tables();
|
||||
}
|
||||
|
||||
@FixFor("DBZ-1833")
|
||||
public void shouldNotUpdateExistingTable() {
|
||||
String ddl = "CREATE TABLE mytable (id INT PRIMARY KEY, val1 INT)";
|
||||
parser.parse(ddl, tables);
|
||||
assertThat(((MySqlAntlrDdlParser) parser).getParsingExceptionsFromWalker().size()).isEqualTo(0);
|
||||
assertThat(tables.size()).isEqualTo(1);
|
||||
|
||||
parser.parse("CREATE TABLE IF NOT EXISTS mytable (id INT PRIMARY KEY, val1 INT, val2 INT)", tables);
|
||||
assertThat(((MySqlAntlrDdlParser) parser).getParsingExceptionsFromWalker().size()).isEqualTo(0);
|
||||
assertThat(tables.size()).isEqualTo(1);
|
||||
|
||||
Table table = tables.forTable(null, null, "mytable");
|
||||
assertThat(table.columns()).hasSize(2);
|
||||
assertThat(table.columnWithName("id")).isNotNull();
|
||||
assertThat(table.columnWithName("val1")).isNotNull();
|
||||
assertThat(table.columnWithName("val2")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FixFor("DBZ-1834")
|
||||
public void shouldHandleQuotes() {
|
||||
@ -2295,7 +2313,8 @@ public void shouldTreatPrimaryKeyColumnsImplicitlyAsNonNull() {
|
||||
assertThat(tableDef.columnWithName("id").hasDefaultValue()).isEqualTo(true);
|
||||
assertThat(tableDef.columnWithName("id").defaultValue()).isEqualTo(0);
|
||||
|
||||
ddl = "CREATE TABLE data(id INT DEFAULT 1, PRIMARY KEY (id))";
|
||||
ddl = "DROP TABLE IF EXISTS data; " +
|
||||
"CREATE TABLE data(id INT DEFAULT 1, PRIMARY KEY (id))";
|
||||
parser.parse(ddl, tables);
|
||||
|
||||
table = tables.forTable(new TableId(null, null, "data"));
|
||||
@ -2317,7 +2336,8 @@ public void shouldTreatPrimaryKeyColumnsImplicitlyAsNonNull() {
|
||||
* @param expectedValues An array of options expected to have been parsed from the expression.
|
||||
*/
|
||||
private void assertParseEnumAndSetOptions(String typeExpression, String... expectedValues) {
|
||||
String ddl = "CREATE TABLE `enum_set_option_test_table` (`id` int not null auto_increment, `options` " +
|
||||
String ddl = "DROP TABLE IF EXISTS enum_set_option_test_table;" +
|
||||
"CREATE TABLE `enum_set_option_test_table` (`id` int not null auto_increment, `options` " +
|
||||
typeExpression + ", primary key(`id`));";
|
||||
|
||||
parser.parse(ddl, tables);
|
||||
|
Loading…
Reference in New Issue
Block a user