diff --git a/docs/src/migration.md b/docs/src/migration.md index 0cfaeea..0b9afa5 100644 --- a/docs/src/migration.md +++ b/docs/src/migration.md @@ -92,7 +92,8 @@ row types `MySQL.TextRow` and `MySQL.BinaryRow` (1.x: `MySQL.TextRow` and `MySQL generated statements only, `debug=:values` also logs row values (1.x `debug=true` logged values). A `DateTime` column is created as `DATETIME(3)` (1.x: `DATETIME`, which dropped the milliseconds); `Timestamp{Second}`/`{Millisecond}`/`{Microsecond}` - columns become `DATETIME`/`DATETIME(3)`/`DATETIME(6)`. + columns become `DATETIME`/`DATETIME(3)`/`DATETIME(6)`. A `Time` column is created as + `TIME(6)` (1.x: `TIME`, which rounded away the fractional seconds). ## Unchanged (Preserve) diff --git a/src/load.jl b/src/load.jl index 2f8e76d..4d8f98c 100644 --- a/src/load.jl +++ b/src/load.jl @@ -31,7 +31,7 @@ const SQLTYPES = Dict{Type, String}( String => "VARCHAR(255)", DataString => "VARCHAR(255)", Date => "DATE", - Time => "TIME", + Time => "TIME(6)", DateTime => "DATETIME(3)", Timestamp{Second} => "DATETIME", Timestamp{Millisecond} => "DATETIME(3)", diff --git a/test/protocol/native_tests.jl b/test/protocol/native_tests.jl index 971220c..90fdde7 100644 --- a/test/protocol/native_tests.jl +++ b/test/protocol/native_tests.jl @@ -5,6 +5,7 @@ struct LocalInfileFunctor end @test N.sqltype(Missing) == "VARCHAR(255)" @test N.sqltype(Any) == "VARCHAR(255)" @test N.sqltype(Union{Missing, Int64}) == "BIGINT" + @test N.sqltype(MySQL.Dates.Time) == "TIME(6)" # TIME(0) would round the fractional seconds @test isempty(Test.detect_unbound_args(MySQL)) end diff --git a/test/user_workflow.jl b/test/user_workflow.jl index 112af38..68599fb 100644 --- a/test/user_workflow.jl +++ b/test/user_workflow.jl @@ -65,6 +65,11 @@ function run_user_workflow(conn) DBInterface.execute(conn, "DROP TABLE IF EXISTS old_dates_load") MySQL.load((id=[1], born=[DateTime(1955, 3, 4)]), conn, "old_dates_load") @test isequal(Tables.columntable(DBInterface.execute(conn, "SELECT born FROM old_dates_load")).born, [Timestamp{Millisecond}(DateTime(1955, 3, 4))]) + # Fractional seconds of a Time column survive MySQL.load (a TIME(0) column rounds them). + DBInterface.execute(conn, "DROP TABLE IF EXISTS times_load") + times = [Time(12, 0, 0, 500), Time(23, 59, 59, 999, 999), Time(0, 0, 0, 0, 1)] + MySQL.load((id=[1, 2, 3], at=times), conn, "times_load") + @test Tables.columntable(DBInterface.execute(conn, "SELECT at FROM times_load ORDER BY id")).at == times @test DBInterface.transaction(conn) do DBInterface.execute(conn, "UPDATE items SET label='changed' WHERE id=1") :committed