I used SQLite3 to implement small application to read from or write to a database. Some records that need to be added to the database are Arabic texts and when they are stored to the database they converted to non-readable and non-understood texts. I use these APIs for write & read:
- sqlite3_open
- sqlite3_prepare
- sqlite3_bind_text
- sqlite3_step
What can I do to solve the problem ?
It is most likely that your text is in non-ASCII encoding. For example, in unicode.
This is because ASCII table has only characters represented by integer numbers from 0 to 127. So there is nothing that can be used to represent Arabic letters. For example, Unicode is using five different ranges to represent Arabic language:
And since there could be more letters/characters that a 8-bit value (
chartype, which has a length of 1 byte) would allow, wide character is used to represent some (or even all) of those letters.As a result, the length of the string in characters will be different from length of the string in bytes. My assumption is that when you use
sqlite3_bind_textfunction, you pass a number of characters as a fourth parameter, whereas it should be a number of bytes. Or you could misinterpret this length when reading the string back from the database. Thesqlite3_bind_textdocumentation is saying this about the fourth parameter:Make sure you do the right thing there.
See also:
Good luck!