diff --git a/src/SQLite.jl b/src/SQLite.jl index 0747a05..3456105 100644 --- a/src/SQLite.jl +++ b/src/SQLite.jl @@ -431,10 +431,12 @@ function bind!(stmt::Stmt, params::DBInterface.NamedStatementParams) SQLiteException("values should be provided for all query placeholders"), ) for i in 1:nparams - name = unsafe_string(C.sqlite3_bind_parameter_name(handle, i)) - isempty(name) && throw( + # a nameless `?` parameter has a NULL name + nameptr = C.sqlite3_bind_parameter_name(handle, i) + nameptr == C_NULL && throw( SQLiteException("nameless parameters should be passed as a Vector"), ) + name = unsafe_string(nameptr) # name is returned with the ':', '@' or '$' at the start sym = Symbol(name[2:end]) haskey(params, sym) || throw( diff --git a/test/runtests.jl b/test/runtests.jl index 5205218..6c6e723 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -594,6 +594,17 @@ end SQLite.clear!(stmt) end + @testset "Named values for a nameless placeholder" begin + db = SQLite.DB() + err = try + DBInterface.execute(db, "SELECT ? AS a", Dict(:a => 1)) + catch e + e + end + @test err isa SQLiteException && occursin("nameless parameters", err.msg) + close(db) + end + @testset "Issue #180, Query" begin param = "Hello!" query = DBInterface.execute(