diff --git a/src/utils.jl b/src/utils.jl index e9db0f6..94a70e1 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -276,7 +276,9 @@ mutable struct Binding b.parametertype = sqltype b.value = Buffer(ctype, columnsize, rows, nullable) b.bufferlength = columnsize - b.strlen_or_indptr = Vector{Int}(undef, rows) + # zeroed: MariaDB Connector/ODBC leaves the indicator of a non-NULL BIT value unwritten in a + # columnar fetch, and leftover memory equal to SQL_NULL_DATA would read as `missing` + b.strlen_or_indptr = zeros(Int, rows) if columnar bindcol(stmt, i, b) end diff --git a/test/runtests.jl b/test/runtests.jl index c2453bb..b02da91 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -490,6 +490,18 @@ for kw in ((;), (iterate_rows=true,)) local ret = DBInterface.execute(conn, "select s from utf8_check order by id"; kw...) |> columntable @test isequal(ret.s, ["ééééé", "abcde", "日本語テキ", "😀😀😀😀😀", missing, "x"]) end +# the driver leaves a non-NULL BIT value's indicator unwritten in a columnar fetch; freed +# memory holding SQL_NULL_DATA (-1) must not turn it into `missing` +DBInterface.execute(conn, "CREATE TABLE bit_check (id INT, b BIT(1))") +DBInterface.execute(conn, "INSERT INTO bit_check SELECT seq, seq % 2 FROM seq_1_to_1000") +for _ in 1:20 + # freed blocks the size of the 1000-row indicator array, and of small ones + local junk = ([fill(-1, 1000) for _ in 1:100], [fill(-1, n) for n in 1:8 for _ in 1:20_000]) + junk = nothing + GC.gc(true) + @test isequal(columntable(DBInterface.execute(conn, "select b from bit_check order by id")).b, isodd.(1:1000)) +end + # a value longer than its column buffer is reported, not read past the buffer @test occursin("6-byte value for a 5-byte column buffer", try ODBC.truncatedvalue(:s, 6, 6) catch e; e.msg end)