magit / emacsql

A high-level Emacs Lisp RDBMS front-end
The Unlicense
552 stars 41 forks source link

Storing null characters #42

Closed tarsius closed 6 years ago

tarsius commented 6 years ago

The sqlite back-end at least does not support storing a string that contains a null character. To allow that we would have to test for such characters and then store the value as a blob instead of as text, I believe.

I found out the hard way, implementing a new sqlite back-end (more on that later) that does not error when a parameter contains a null character - only to learn that this results in the text after the null character to be lost.

For the time being I just strip the null character from user values and that's good enough for me, but I am reporting this because its worth knowing that due to this issue Emacsql does not actually support all readable values.

skeeto commented 6 years ago

Yup, you're right. It looks like the NUL character is not supported in SQLite strings at all. They're only supported in blobs. The SQLite docs say this:

The result of expressions involving strings with embedded NULs is undefined.

Fortunately this doesn't matter to EmacSQL. It's just a matter of escaping the NUL character and letting the lisp reader deal with it. Fixed in 3b70e8f.