From 0583356d992d226edfed37a49fac51d435a37f8e Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Thu, 19 Nov 2026 12:23:58 -0700 Subject: [PATCH] Keep only text and BLOB values in a statement's bound parameters `bind!` stored every bound value in `stmt.params`, a `Dict{Int,Any}` that keeps values alive while SQLite reads them. SQLite copies numbers and NULLs when they are bound, so storing them only boxed each value and hashed it into the Dict, once per value in every `load!`, `execute`, and `executemany` call. Numeric, Bool, `missing`, and `nothing` values are no longer stored. Text and BLOB values, which SQLite reads in place, still are. Co-Authored-By: Claude Opus 5.5 --- src/SQLite.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/SQLite.jl b/src/SQLite.jl index 7088b1a..4e5466f 100644 --- a/src/SQLite.jl +++ b/src/SQLite.jl @@ -278,7 +278,7 @@ With `register=false`, the caller remains responsible for closing the statement. mutable struct Stmt <: DBInterface.Statement db::DB stmt_wrapper::StmtWrapper - # used for holding references to bound statement values via bind! + # bound text and BLOB values, kept alive while SQLite reads them in place params::Dict{Int,Any} # current row number of the newest query on this statement; -1 once its run has ended cursor::Base.RefValue{Int} @@ -475,7 +475,6 @@ end # binding method for internal _Stmt class function bind!(stmt::Stmt, i::Integer, val::AbstractFloat) - stmt.params[i] = val @CHECK stmt.db C.sqlite3_bind_double( _get_stmt_handle(stmt), i, @@ -483,20 +482,16 @@ function bind!(stmt::Stmt, i::Integer, val::AbstractFloat) ) end function bind!(stmt::Stmt, i::Integer, val::Int32) - stmt.params[i] = val @CHECK stmt.db C.sqlite3_bind_int(_get_stmt_handle(stmt), i, val) end function bind!(stmt::Stmt, i::Integer, val::Int64) - stmt.params[i] = val @CHECK stmt.db C.sqlite3_bind_int64(_get_stmt_handle(stmt), i, val) end bind!(stmt::Stmt, i::Integer, val::Integer) = bind!(stmt, i, Int64(val)) function bind!(stmt::Stmt, i::Integer, val::Missing) - stmt.params[i] = val @CHECK stmt.db C.sqlite3_bind_null(_get_stmt_handle(stmt), i) end function bind!(stmt::Stmt, i::Integer, val::Nothing) - stmt.params[i] = val @CHECK stmt.db C.sqlite3_bind_null(_get_stmt_handle(stmt), i) end # `val` converted for a `Ptr{Cchar}` argument, and the length of its UTF-8 text in bytes. @@ -539,7 +534,6 @@ function bind!(stmt::Stmt, i::Integer, val::WeakRefString{UInt16}) ) end function bind!(stmt::Stmt, i::Integer, val::Bool) - stmt.params[i] = val @CHECK stmt.db C.sqlite3_bind_int(_get_stmt_handle(stmt), i, Int32(val)) end function bind!(stmt::Stmt, i::Integer, val::Vector{UInt8})