This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author petri.lehtinen
Recipients ghaering, petri.lehtinen
Date 2011-12-29.12:27:33
SpamBayes Score 1.83426e-08
Marked as misclassified No
Message-id <>
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')
# 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:35petri.lehtinensetrecipients: + petri.lehtinen, ghaering
2011-12-29 12:27:34petri.lehtinensetmessageid: <>
2011-12-29 12:27:34petri.lehtinenlinkissue13676 messages
2011-12-29 12:27:33petri.lehtinencreate