SQLITE_RANGE
SQLiteERRORNotableAPI Misuseofficial confidence
Bind or column index out of range
Production Risk
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.
trigger — this will error
trigger — this will error
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_RANGEexpected output
In C: SQLITE_RANGE; in Python driver: IndexError or similar.
Fix 1
Fix 2
Fix 3
What not to do
✕
Sources
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev