Message150329
| Author |
petri.lehtinen |
| Recipients |
ghaering, petri.lehtinen |
| Date |
2011年12月29日.12:27:33 |
| SpamBayes Score |
1.834258e-08 |
| Marked as misclassified |
No |
| Message-id |
<1325161654.99.0.774888973707.issue13676@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|