Skip to content

Commit

Permalink
Merge pull request #168 from zendesk/ben/time_stuff
Browse files Browse the repository at this point in the history
some Time fixes / improvements
  • Loading branch information
Ben Osheroff committed Nov 27, 2015
2 parents e3b3d7c + 744e3d5 commit 1f9ac04
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/antlr4/imports/column_definitions.g4
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ data_type:

// all from http://dev.mysql.com/doc/refman/5.1/en/create-table.html
generic_type:
col_type=(BIT | BINARY | YEAR) length? column_options*
| col_type=(DATE | TIME | TIMESTAMP | DATETIME | TINYBLOB | MEDIUMBLOB | LONGBLOB | BLOB | BOOLEAN | BOOL ) column_options*
col_type=(BIT | BINARY | YEAR | TIME | TIMESTAMP | DATETIME) length? column_options*
| col_type=(DATE | TINYBLOB | MEDIUMBLOB | LONGBLOB | BLOB | BOOLEAN | BOOL ) column_options*
| col_type=VARBINARY length column_options*
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public String toSQL(Object value) {
return "'" + String.valueOf(t) + "'";
}

@Override
public Object asJSON(Object value) {
return String.valueOf((Time) value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void testSetJSON() throws Exception {

@Test
public void testZeroCreatedAtJSON() throws Exception {
if ( server.getVersion().equals("5.5") ) // 5.6 not yet supported.
if ( server.getVersion().equals("5.5") ) // 5.6 not yet supported for this test
runJSONTestFile(getSQLDir() + "/json/test_zero_created_at");
}

Expand All @@ -323,4 +323,10 @@ public void testBit() throws Exception {
public void testBignum() throws Exception {
runJSONTestFile(getSQLDir() + "/json/test_bignum");
}

@Test
public void testTime() throws Exception {
if ( server.getVersion().equals("5.6") )
runJSONTestFile(getSQLDir() + "/json/test_time");
}
}
1 change: 1 addition & 0 deletions src/test/resources/sql/json/test_1j
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ delete from test_table;
-> {"database": "test_db_1", "table": "test_table", "type": "delete", "data": {"id": 2, "textcol": "test_col_2"} }
-> {"database": "test_db_1", "table": "test_table", "type": "delete", "data": {"id": 3, "textcol": "test_col_2", "datecol": "1979-10-01 00:00:00"} }


DROP DATABASE `test_db_1`;

12 changes: 12 additions & 0 deletions src/test/resources/sql/json/test_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
create database timedb
use timedb

set global time_zone = '-0:00';

CREATE TABLE tt ( t time(6), dt datetime(3), ts timestamp(4) NULL );

insert into tt set t = '12:23:33.222', dt = '2012-01-01 22:32:34.222';

# TODO: support fractional times properly!
-> { "database": "timedb", "table": "tt", "type": "insert", "data": {"t": "12:23:33", "dt": "2012-01-01 22:32:34" } }

0 comments on commit 1f9ac04

Please sign in to comment.