A.J.Millan wrote:
> Thanks for your answer; let me see if I understood correctly the process:
> 
> [1] Read the actual textual data with sqlite3_column_blob()
> 
> [2] Assuming the system code page matches the one used when the data was
> originally inserted, convert with mbstowcs()
> 
> [3] (Doubt) The result can be directly written with sqlite3_bind_text() -I
> want store in UTF-8-

The result can be passed to sqlite3_bind_text16. If the database's encoding is 
in fact UTF-8 (determined when the database file is originally created), SQLite 
will convert your string to UTF-8 automatically. If the database's encoding is 
UTF-16, the string will be inserted as-is.

The original call to sqlite3_open{16,_v2} which created the database file in 
the first place determines its encoding. After that, it doesn't matter which 
API calls you use: SQLite will convert strings to the database encoding as 
necessary. Pass UTF-16 strings to *16 versions of API accepting void*, UTF-8 to 
versions accepting char*.

> [4] Afterward once converted the dBase and in regular use:
> 
> [4-1a] Read with sqlite3_column_text()

... if you want UTF-8 strings back, or with sqlite3_column_text16 if you want 
UTF-16 strings back. Figure out which way you want to handle strings in your 
own code.

> [4-1b] convert with WideCharToMultiByte(CP_UTF8)

sqlite3_column_text will give you UTF-8 already, no conversion necessary.

> [4-1c] Use the result with Win32 api -SetTex()-

The only Win32 API function that can handle UTF-8 strings is 
MultiByteToWideChar (when called with CP_UTF8 flag). You should have a Unicode 
build, where Win32 API takes UTF-16.

> OR?
> 
> [4-2a] Read with sqlite3_column_text16()
> [4-2b] No convertion needed.
> [4-2c] Use the result ...

Yes, this should work, assuming that "use the result" part actually knows how 
to deal with UTF-16.

Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to