>>>Every SQLite database file has a text encoding that applies to the entire
file:  one of utf8, utf16be, or utf16le.  The database text encoding is
stored in the header.  You can see the encoding for a particular database
using:

     sqlite3 DATABASE.db .dbinfo

>>>(NB: The ".dbinfo" command is relatively recent, so you'll want the
latest version of sqlite3.exe for this to work.)

Mine is 3.8.6 2014-08-15 11:46:33 9491ba7d738528f168657adb43a198238abde19e.
I guess I need something newer. That does explain why I couldn't find out.

>>>All text store in the database file uses the database text encoding.
*All Text*.  So if your database encoding is UTF16 and you do
"sqlite3_bind_text()" then SQLite automatically converts your UTF8 input
into UTF16 before storing it.  Or if you do "sqlite3_column_text()", then
SQLite will convert from UTF16 to UTF8 before returning the answer.

>>>Obviously, in order to avoid unnecessary conversions, it works best if
the database encoding matches the encoding most commonly used by your
application.

OK, I get it. I don't want to enforce an encoding, I just want it to work
with any database.

I use the C API from C# using P/Invoke, and there doesn't seem to be any
native way to do utf-8 marshalling. It would seem the best result might be
to use the text16() family [such as sqlite3_value_text16()]. There is
marshalling from 'Unicode', which is Windows for utf-16, and that should be
reasonably efficient (compared to trying to do it in managed space).I'll ask
that one over on Stack Overflow. Thanks for the tips.

Regards
David M Bennett FACS

Andl - A New Database Language - andl.org





Reply via email to