New submission from Petri Lehtinen <pe...@digip.org>: 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. ---------- components: Library (Lib) files: sqlite3_zero_byte.patch keywords: needs review, patch messages: 150329 nosy: ghaering, petri.lehtinen priority: normal severity: normal status: open title: sqlite3: Zero byte truncates string contents type: behavior versions: Python 2.7, Python 3.2, Python 3.3 Added file: http://bugs.python.org/file24104/sqlite3_zero_byte.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13676> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com