Skip to content

Commit

Permalink
Merge pull request #68 from zendesk/ben/bugs
Browse files Browse the repository at this point in the history
fix misc bugs
  • Loading branch information
Ben Osheroff committed Jun 18, 2015
2 parents 8ecc9bc + cff03ba commit b361e0c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/antlr4/imports/column_definitions.g4
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ data_type:

// from http://dev.mysql.com/doc/refman/5.1/en/create-table.html
generic_type: // types from which we're going to ignore any flags/length
col_type=(BIT | BINARY) length?
| col_type=(DATE | TIME | TIMESTAMP | DATETIME | YEAR | TINYBLOB | MEDIUMBLOB | LONGBLOB | BLOB )
col_type=(BIT | BINARY | YEAR) length?
| col_type=(DATE | TIME | TIMESTAMP | DATETIME | TINYBLOB | MEDIUMBLOB | LONGBLOB | BLOB | BOOLEAN | BOOL )
| col_type=VARBINARY length
;


signed_type: // we need the UNSIGNED flag here
col_type=(TINYINT | INT1 | SMALLINT | INT2 | MEDIUMINT | INT3 | INT | INTEGER | INT4 | BIGINT | INT8 )
length?
Expand Down
3 changes: 3 additions & 0 deletions src/main/antlr4/imports/generate_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
NULL
NO
ACTION

BOOL
BOOLEAN
)

tokens_allowed_in_names = []
Expand Down
4 changes: 3 additions & 1 deletion src/main/antlr4/imports/mysql_literal_tokens.g4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
grammar mysql_literal_tokens;

tokens_available_for_names: (ACTION | AFTER | AUTO_INCREMENT | AVG_ROW_LENGTH | BEGIN | BIT | BTREE | CHARSET | CHECKSUM | COLUMN_FORMAT | COMMENT | COMPACT | COMPRESSED | CONNECTION | DATA | DATE | DATETIME | DELAY_KEY_WRITE | DIRECTORY | DISABLE | DISK | DYNAMIC | ENABLE | ENGINE | ENUM | FIRST | FIXED | FULL | HASH | INSERT_METHOD | KEY_BLOCK_SIZE | LAST | MAX_ROWS | MEMORY | MIN_ROWS | MODIFY | NO | OFFLINE | ONLINE | PACK_KEYS | PARSER | PARTIAL | PASSWORD | REDUNDANT | ROW_FORMAT | SIMPLE | STORAGE | TABLESPACE | TEMPORARY | TEXT | TIME | TIMESTAMP | YEAR);
tokens_available_for_names: (ACTION | AFTER | AUTO_INCREMENT | AVG_ROW_LENGTH | BEGIN | BIT | BOOL | BOOLEAN | BTREE | CHARSET | CHECKSUM | COLUMN_FORMAT | COMMENT | COMPACT | COMPRESSED | CONNECTION | DATA | DATE | DATETIME | DELAY_KEY_WRITE | DIRECTORY | DISABLE | DISK | DYNAMIC | ENABLE | ENGINE | ENUM | FIRST | FIXED | FULL | HASH | INSERT_METHOD | KEY_BLOCK_SIZE | LAST | MAX_ROWS | MEMORY | MIN_ROWS | MODIFY | NO | OFFLINE | ONLINE | PACK_KEYS | PARSER | PARTIAL | PASSWORD | REDUNDANT | ROW_FORMAT | SIMPLE | STORAGE | TABLESPACE | TEMPORARY | TEXT | TIME | TIMESTAMP | YEAR);


INT1: I N T '1';
Expand All @@ -21,6 +21,8 @@ BIGINT: B I G I N T;
BINARY: B I N A R Y;
BIT: B I T;
BLOB: B L O B;
BOOL: B O O L;
BOOLEAN: B O O L E A N;
BTREE: B T R E E;
BY: B Y;
CASCADE: C A S C A D E;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static ColumnDef build(String tableName, String name, String encoding, St
type = unalias_type(type);

switch(type) {
case "bool":
case "boolean":
type = "tinyint";
// fallthrough
case "tinyint":
case "smallint":
case "mediumint":
Expand All @@ -51,6 +55,9 @@ public static ColumnDef build(String tableName, String name, String encoding, St
case "mediumblob":
case "longblob":
return new StringColumnDef(tableName, name, type, pos, "binary");
case "real":
type = "double";
// fall through
case "float":
case "double":
return new FloatColumnDef(tableName, name, type, pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public abstract class SchemaChange {
SQL_BLACKLIST.add(Pattern.compile("^ANALYZE\\s+TABLE", Pattern.CASE_INSENSITIVE));
SQL_BLACKLIST.add(Pattern.compile("^SET\\s+PASSWORD", Pattern.CASE_INSENSITIVE));
SQL_BLACKLIST.add(Pattern.compile("^(CREATE|DROP|RENAME)\\s+USER", Pattern.CASE_INSENSITIVE));

SQL_BLACKLIST.add(Pattern.compile("^TRUNCATE\\s+TABLE", Pattern.CASE_INSENSITIVE));
}

private static boolean matchesBlacklist(String sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,32 @@ public void testIntX() throws Exception {
};

testIntegration(sql);
}

@Test
public void testYearWithLength() throws Exception {
String sql[] = {
"create TABLE `test_year` ( id year(4) )"
};

testIntegration(sql);
}

@Test
public void testBooleans() throws Exception {
String sql[] = {
"create TABLE `test_boolean` ( b1 bool, b2 boolean )"
};

testIntegration(sql);
}

@Test
public void testReals() throws Exception {
String sql[] = {
"create TABLE `test_reals` ( r1 REAL, b2 REAL (2,2) )"
};

testIntegration(sql);
}
}

0 comments on commit b361e0c

Please sign in to comment.