Skip to content

Commit 31465d1

Browse files
authored
Allow sqldeserialize to return non-T to allow value/schema mismatch (#267)
Fixes #244. Last time we refactored SQLite.Query, we took out any strict schema enforcement, mainly by defining the `Tales.schema` of `SQLite.Query` to be `nothing`, thus allowing sinks to "discover" the schema dynamically, which better fits the sqlite data type model. As reported in #244, however, we missed a case where we pass in the declared column's type to `sqlitevalue` and then `sqldeserialize` was being forced to assert that what it deserialized was a value of that type. That isn't generally possible, since the declared sqlite types are such a small subset of what we'll technically serialize/deserialize with custom Julia values. By removing the type assertion, we allow sqldeserialize to do its job and sqlitevalue to return whatever gets deserialized.
1 parent 735d3fe commit 31465d1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/SQLite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ function sqlitevalue(::Type{T}, handle, col) where {T}
414414
b = sqlite3_column_bytes(handle, col)
415415
buf = zeros(UInt8, b) # global const?
416416
unsafe_copyto!(pointer(buf), blob, b)
417-
r = sqldeserialize(buf)::T
417+
r = sqldeserialize(buf)
418418
return r
419419
end
420420

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,11 @@ tbl = DBInterface.execute(db, "select * from tmp") |> columntable
559559
c = [6]
560560
)
561561

562+
db = SQLite.DB()
563+
DBInterface.execute(db, "create table tmp ( x TEXT )")
564+
DBInterface.execute(db, "insert into tmp values (?)", (nothing,))
565+
DBInterface.execute(db, "insert into tmp values (?)", (:a,))
566+
tbl = DBInterface.execute(db, "select x from tmp") |> columntable
567+
@test isequal(tbl.x, [missing, :a])
568+
562569
end

0 commit comments

Comments
 (0)