Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relax bind! Vector{UInt8} -> AbstractVector{UInt8} #340

Merged
merged 5 commits into from
May 22, 2024
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
10 changes: 10 additions & 0 deletions src/SQLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ function bind!(stmt::Stmt, i::Integer, val::Vector{UInt8})
C.SQLITE_STATIC,
)
end
function bind!(stmt::Stmt, i::Integer, val::Base.ReinterpretArray{UInt8, 1, T, <:DenseVector{T}, false}) where T
stmt.params[i] = val
@CHECK stmt.db C.sqlite3_bind_blob(
_get_stmt_handle(stmt),
i,
Ref(val, 1),
sizeof(eltype(val)) * length(val),
C.SQLITE_STATIC,
)
end
# Fallback is BLOB and defaults to serializing the julia value

# internal wrapper mutable struct to, in-effect, mark something which has been serialized
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,24 @@ end
close(db)
rm(dbfile)
end

@testset "ReinterpretArray" begin
binddb = SQLite.DB()
DBInterface.execute(
binddb,
"CREATE TABLE temp (b BLOB)",
)
DBInterface.execute(
binddb,
"INSERT INTO temp VALUES (?)",
[reinterpret(UInt8, [0x6f46, 0x426f, 0x7261]),],
)
rr = DBInterface.execute(rowtable, binddb, "SELECT b FROM temp")
@test length(rr) == 1
r = first(rr)
@test r.b == codeunits("FooBar")
@test typeof.(Tuple(r)) == (Vector{UInt8},)
end
end # @testset

struct UnknownSchemaTable end
Expand Down