Suppose I have a table with one text column. I insert like this:

INSERT INTO my_table (col1) VALUES ('arbitrary UTF-8 string');

* Isn't it true that the string must indeed be surrounded by single quotes as I 
do above?
* Isn't it true that I have to replace all occurrences of ' in the original 
string with '' (to escape each single quote)?
* Do I have to do anything else at all?

I never know how to answer questions starting in the negative.
Do I answer "Yes it isn't", or "No it isn't"?

Basically if you don't wish to or cannot use the SQLite Prepare-Bind-Step sequencing, a simple execute will do the trick (which is equal to the alternative except with you wielding less control).

One note of caution (since your question is very reminscent of one who is having UTF-8 troubles and double-checking his work) - Some systems / Platforms do not use UTF-8 natively or use some kind of intermediary thing that is typically ANSI-based and translates easily into UTF-8 or UTF-16 or Unicode. (unless it is really old). Windows/Linux/OSX/etc. all provide native routines for translating text into different code-pages, but I found some of those fail and simply yield an empty result as opposed to an error when encountering specific invalid characters (or more specifically, incorrect byte-sequence) for the requested formatting.
(I cannot speak much for the embedded community, but I'm sure parrallel issues 
exist.)

SQLite can bind values in both UTF-8 type character arrays or UTF-16 type (there are different functions for it) but it must be already correctly encoded and also be aware that a database file might be in a non-UTF-8 format and you cannot change this after a Schema is added [*Citation needed].
See: http://www.sqlite.org/pragma.html#pragma_encoding

I hope this helps your quest.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to