Check the encoding of text in SQlite

后端 未结 1 856
别那么骄傲
别那么骄傲 2020-12-06 05:13

I\'m having a nightmare dealing with non Eurpean texts in SQlite. I think the problem is that SQlite isn\'t encoding the text in UTF8. So I want to check what the encoding i

相关标签:
1条回答
  • 2020-12-06 05:53

    You can test the encoding with this pragma:

    PRAGMA encoding; 
    

    You cannot change the encoding for an existing database. To create a new database with a specific encoding, open a SQLite connection to a blank file, run this pragma:

    PRAGMA encoding = "UTF-8"; 
    

    And then create your database.

    If you have a database and need a different encoding, then you need to create a new database with the new encoding, and then recreate the schema and import all the data.

    However, if you have a problem with garbled text it's pretty much always a problem with one of the tools being used, not SQLite itself. Even if SQLite is using a different encoding depending, the only end result is that it will cause some extra computation as SQLite converts from stored encoding to API-requested encoding constantly. If you're using anything other than the C-level API's, then you should never care about encoding--the API's used by the tool you're using will dictate what encoding should be used.

    Many SQLite tools have shown issues mangling text into our out of SQLite, including command line shells. Try running SQLite from a command line and tell it to import the file itself instead of going through SQLite Browser.

    0 讨论(0)
提交回复
热议问题