Analysis and solution of Chinese garbled characters appearing in SQLite
When we use the SQLite database, we may find that when inserting data to the database is displayed when the Chinese characters, but read through SQLite is garbled, this is because the SQLite database is supported by the encoding method is not the same as in our program, SQLite database is UTF-8 encoding, and we often use in the program is a wide-byte uncoid encoding, so the use of SQLite database read out will be garbled, because the encoding is not the same, for example, based on a dialog box program, We want to display the data we read in our database on the Listctrl control, and when we write the program to read it, the list control shows unreadable garbled characters, which is why.
For example, in VC + + through the Sqlite3.dll interface to the SQLite database operation, including open database, insert, query database, etc., if the operation interface input parameter contains Chinese characters, will cause the operation exception. For example, calling Sqlite3_open to open the database file, if the file path appears in Chinese, will cause the open to fail. SQLITE3_EXEC executes the SQL statement, and if it contains Chinese characters it will become garbled.
There is definitely a problem to solve, I beginner sqlite, by looking for information, this is because the SQLite database uses UTF-8 encoding, and the incoming string is ASCII encoding or Unicode encoding, resulting in a string format error. The solution is to convert the string to UTF-8 encoding before invoking the SQLite interface, which provides a variety of string encoding conversion functions: The functions are as follows:
in general, we use VC + + programming when the most used function is UTF-8 to Unicode, the function is for reference only
Solving the problem of Chinese garbled database in SQLite