Message150329
Inserting a string with embedded zero byte only inserts the string up to the first zero byte:
import sqlite3
connection = sqlite3.connect(':memory:')
cursor = connection.cursor()
cursor.execute('CREATE TABLE test (value TEXT)')
cursor.execute('INSERT INTO test (value) VALUES (?)', ('foo\x00bar',))
cursor.execute('SELECT value FROM test')
print(cursor.fetchone())
# expected output: (u'foo\x00bar',)
# actual output: (u'foo',)
Also, if there's already data inserted to a table like above with embedded zero bytes, the sqlite-API-to-Python-string conversion truncates the strings to just before the first zero byte.
Attaching a patch against 3.3 that fixes the problem. Basically, it uses PyUnicode_AsStringAndSize and PyUnicode_FromStringAndSize instead of the non-size variants.
Please review, as I'm not sure it covers each possible case. |
|
Date |
User |
Action |
Args |
2011-12-29 12:27:35 | petri.lehtinen | set | recipients:
+ petri.lehtinen, ghaering |
2011-12-29 12:27:34 | petri.lehtinen | set | messageid: <1325161654.99.0.774888973707.issue13676@psf.upfronthosting.co.za> |
2011-12-29 12:27:34 | petri.lehtinen | link | issue13676 messages |
2011-12-29 12:27:33 | petri.lehtinen | create | |
|