Skip to content

Commit fb9fced

Browse files
quinnjclaude
andauthored
Zero the fetch indicator arrays (#412)
MariaDB Connector/ODBC leaves the length/indicator of a non-NULL BIT value unwritten in a columnar fetch. The indicator array was allocated uninitialized, so whenever its memory held -1 (SQL_NULL_DATA) from earlier use, a stored true/false read back as missing. This was the intermittent ODBC.load round-trip failure in CI (Senior read as [true, true, false, missing]). Zeroed indicators read a value the driver didn't mark as non-NULL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 93865fb commit fb9fced

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/utils.jl‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ mutable struct Binding
276276
b.parametertype = sqltype
277277
b.value = Buffer(ctype, columnsize, rows, nullable)
278278
b.bufferlength = columnsize
279-
b.strlen_or_indptr = Vector{Int}(undef, rows)
279+
# zeroed: MariaDB Connector/ODBC leaves the indicator of a non-NULL BIT value unwritten in a
280+
# columnar fetch, and leftover memory equal to SQL_NULL_DATA would read as `missing`
281+
b.strlen_or_indptr = zeros(Int, rows)
280282
if columnar
281283
bindcol(stmt, i, b)
282284
end

‎test/runtests.jl‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,18 @@ for kw in ((;), (iterate_rows=true,))
490490
local ret = DBInterface.execute(conn, "select s from utf8_check order by id"; kw...) |> columntable
491491
@test isequal(ret.s, ["ééééé", "abcde", "日本語テキ", "😀😀😀😀😀", missing, "x"])
492492
end
493+
# the driver leaves a non-NULL BIT value's indicator unwritten in a columnar fetch; freed
494+
# memory holding SQL_NULL_DATA (-1) must not turn it into `missing`
495+
DBInterface.execute(conn, "CREATE TABLE bit_check (id INT, b BIT(1))")
496+
DBInterface.execute(conn, "INSERT INTO bit_check SELECT seq, seq % 2 FROM seq_1_to_1000")
497+
for _ in 1:20
498+
# freed blocks the size of the 1000-row indicator array, and of small ones
499+
local junk = ([fill(-1, 1000) for _ in 1:100], [fill(-1, n) for n in 1:8 for _ in 1:20_000])
500+
junk = nothing
501+
GC.gc(true)
502+
@test isequal(columntable(DBInterface.execute(conn, "select b from bit_check order by id")).b, isodd.(1:1000))
503+
end
504+
493505
# a value longer than its column buffer is reported, not read past the buffer
494506
@test occursin("6-byte value for a 5-byte column buffer", try ODBC.truncatedvalue(:s, 6, 6) catch e; e.msg end)
495507

0 commit comments

Comments
 (0)