SQLITE_RANGEERRORTier 2 — Caution⚠️ MEDIUM confidenceBind or column index out of range
🔴 Production Risk Error
Medium — causes data to not be bound, leading to unexpected NULL values or errors.
What this means
SQLITE_RANGE (25) is returned when the second argument to sqlite3_bind_*() or sqlite3_column_*() is out of range. Column and parameter indices are 1-based in the C API.
Why it happens
- 1Passing a parameter index of 0 or greater than the number of bind parameters.
- 2Accessing a column index beyond the number of columns in the result set.
- 3Off-by-one error in C extension code — SQLite bind indices start at 1, not 0.
How to reproduce
sqlite3_bind_*() and sqlite3_column_*() calls with invalid indices.
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE t(a,b)')
conn.execute('INSERT INTO t VALUES(?,?)', (1, 2))
cur = conn.execute('SELECT a FROM t')
row = cur.fetchone()
# Python driver abstracts index; in C API:
# sqlite3_column_int(stmt, 5) on a 1-column result → SQLITE_RANGEFix 1
Why this works
In C code, ensure bind indices are in the range [1, sqlite3_bind_parameter_count()].
Fix 2
Why this works
Ensure column indices are in the range [0, sqlite3_column_count()-1] for sqlite3_column_*().
Fix 3
Why this works
Use sqlite3_bind_parameter_name() to verify named parameters.
What not to do
Why it's wrong:
Sources
📚 Official docs: https://www.sqlite.org/rescode.html#range
🔧 Source ref: sqlite3.h — SQLITE_RANGE = 25
📖 Further reading: sqlite3_bind_*()
Confidence assessment
⚠️ MEDIUM confidence
Stable.
See also
📄 Reference pages