Double check your database schema. As described in Datatypes in SQLite Version 3 , a column type name affects how values ββare processed before saving.
Here's a Python program to demonstrate using a database in memory:
import sqlite3 db = sqlite3.connect(':memory:') val = "0796"; db.execute('CREATE TABLE test (i INTEGER, r REAL, t TEXT, b BLOB);') db.execute('INSERT INTO test VALUES (?, ?, ?, ?);', (val, val, val, val)) res = db.execute('SELECT * FROM test'); print '\t'.join([x[0] for x in res.description]) for row in res.fetchall(): print '\t'.join([repr(x) for x in row])
Output:
irtb 796 796.0 u'0796' u'0796'
So it looks like your column is an integer type. Take a look at the schema definition ( sqlite3 database.db .schema works from the command line), again look at the documentation and make sure that you use one type name that maps to TEXT affinity. Unknown type names get an INTEGER binding.
In my own case, I used "STR", which ends with the default INTEGER binding. I changed it to TEXT and SQLite began to respect my leading zeros.
jwhitlock
source share