Solving the problem of Chinese garbled database in SQLite

Source: Internet
Author: User
Tags sqlite database string format

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.