Skip to content

Commit 42c9c3d

Browse files
authored
don't try deserializing short blobs (#249)
* don't try deserializing short blobs * use first() instead of only()
1 parent 25f3702 commit 42c9c3d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/SQLite.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ end
328328
const SERIALIZATION = sqlserialize(0)[1:18]
329329

330330
function sqldeserialize(r)
331+
if sizeof(r) < sizeof(SERIALIZATION)
332+
return r
333+
end
331334
ret = ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt),
332335
SERIALIZATION, r, min(sizeof(SERIALIZATION), sizeof(r)))
333336
if ret == 0

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ end
458458
SQLite.drop!(db, "bool_data");
459459
end
460460

461+
@testset "serialization edgecases" begin
462+
db = SQLite.DB()
463+
r = DBInterface.execute(db, "SELECT zeroblob(2) as b") |> columntable
464+
@test first(r.b) == [0, 0]
465+
r = DBInterface.execute(db, "SELECT zeroblob(0) as b") |> columntable
466+
@test first(r.b) == []
467+
end
468+
461469
@testset "Stmt scope" begin
462470
dbfile = joinpath(tempdir(), "test_stmt_scope.sqlite")
463471
db = SQLite.DB(dbfile)

0 commit comments

Comments
 (0)