SQLite

View Ticket
Login
2011-10-31
18:44 Closed ticket [57c971fc74]: Some user defined string functions do not operate correctly on strings with embedded nuls (artifact: 6cae2ae2a4 user: drh)
2011-10-13
18:01 Fixed ticket [57c971fc74]. (artifact: b5983b3d0b user: drh)
18:00
Simplifications to the upper() and lower() SQL functions. Updates to documentation on sqlite3_bind_text() and sqlite3_result_text() to make it clear that users should not try to create strings with embedded NULs and that if they do the result of expression on those strings is undefined. Ticket [57c971fc74524a] (check-in: 9984cc20ca user: drh tags: trunk)
2011-09-26
23:07 New ticket [57c971fc74] Some user defined string functions do not operate correctly on strings with embedded nuls. (artifact: e916c2f4a1 user: rogerb)

Ticket Hash: 57c971fc74524aa46e0b367dbed9a9a77aed4ebc
Title: Some user defined string functions do not operate correctly on strings with embedded nuls
Status: Closed Type: Code_Defect
Severity: Minor Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2011-10-31 18:44:32
13.68 years ago
Created: 2011-09-26 23:07:40
13.78 years ago
Version Found In: 3.7.8
Description:
SQLite supports embedded NUL in strings, both via the C API and SQL. For example this will create one:
INSERT INTO table VALUES('abc' || x'00' || 'def');

Many of the user defined string functions such as quote, upper/lower, length, replace, (r)trim stop their operations at the first NUL rather than at the end of the string.

Somewhat related you can also create UTF16 sequences with odd numbers of bytes using the insert sequence above because || operates on bytes not characters.

This topic was discussed on the mailing list:

http://thread.gmane.org/gmane.comp.db.sqlite.general/68307/focus=68400

drh added on 2011-10-13 18:01:28:
Updated documentation to try to make it clearer that the result of expressions involving strings with embedded NUL characters is undefined. Also added more detail to the documentation on sqlite3_prepare(), sqlite3_bind_text(), and sqlite3_result_text() to try to clear up confusion about the use of NUL terminators.