-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/09/2010 10:54 AM, Eric Smith wrote: > My question came purely from a mild curiosity. I was wondering about > the behavior of sqlite call sqlite3_bind_text when it is passed a range > of BYTES that includes nulls.
bind_text and bind_blob use the same backend function, passing it their parameters (byte pointer and length) as well as an encoding parameter (0 for blob, SQLITE_UTF8 or SQLITE_UTF16NATIVE). If the encoding doesn't match the database encoding then it is changed. The important thing is that the bytes are taken exactly as is. They are not looked at unless the encoding needs to be changed. The routine to change encoding (sqlite3VdbeMemTranslate) does not return an error if the bytes are not actually valid UTF8/16. In other words if you give SQLite something claiming it is a string then SQLite takes you at your word and does not do a round of double checking. It will return that same "string" when retrieving that value (ie same length and byte sequence). This is why you can include embedded nulls. It is also why you can feed it bytes in IS8859-1 and things will seem to be okay. (One of the Python wrappers allows that!) Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkw3aWoACgkQmOOfHg372QT3vACgtVRoq/l8HZeDLd/QYwdt50NN qZ0AoM48Qu3ubM3Ld3FfQMjnyxv/WJkA =i6MM -----END PGP SIGNATURE----- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users