SQLite - encoding issues

149 views Asked by At

I’m writing an application using SQLite and whenever I insert Spanish characters I get this kind of strings: Mart�n (where it should read ‘Martín’)

Ok, so if I open my database with SQLiteManager (the Firefox addin) my strings look weird like that. But SQLiteManager is able to insert and display any string correctly. And any string inserted by SQLiteManager displays all right in my app as well.

So I must be doing something wrong when I insert the strings. This is my code:

char szAux[512];
ZeroMemory(szAux, 512);
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, szSQL, wcslen(szSQL), szAux, 512, NULL, 0);
int nRet= sqlite3_exec(m_hDB, szAux, NULL, 0, &pErrMsg);

Note: szSQL is the wchar-string my app uses and after the call to WideCharToMultiByte() contains the following: "INSERT INTO numeros VALUES (1, 'Martín','Sonny', '123-123123', '[email protected]', -1, 0, 1482036037, 125.500000)"

SQLiteManager tells me that my db is utf-16le. Im using vs2015 in a Windows10 64bit machine.

I’d appreciate any help. Thanks in advance!

1

There are 1 answers

0
CL. On BEST ANSWER

The SQLite functions use the UTF-8 encoding.

CP_ACP is something different. Use CP_UTF8.

(The database encoding just specifies how text is stored in the database file, but does not affect any API functions. Using utf-16le just makes it inefficient.)