Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading