In my application, I have the need to store strings with non-latin characters in a SQLite database. But when I insert them, they become corrupt.When i bind the string to the prepared statement, i do make sure it is in UTF-8: sqlite3_bind_text(sentence_insert_statement, 1, [string UTF8String], -1, SQLITE_TRANSIENT); //Where "string" is the string i am trying to insert. I thought that might be the problem of SQLite itself, but when I make an sql file in the UTF-8 encoding, like 'insert into sentences (sentence) values ("пÑивеÑ");' and perform .read (the name of my sql file), it works absolutely fine. Am I missing something important when inserting strings to my db programmatically?
Others have pointed out the appropriate NSString methods to deal with the encoding issues.
But your problems go much deeper here. SQLite is a C level API, and while it will preserve UTF-8 and UTF-16 characters if you use the correct APIs, none of its queries support fully locale aware Unicode compliant searching or sorting. If you want to query against Unicode text, you will need to write your own custom functions that use ICU, and register them with SQLite. It's a lot of work, and it is significantly nontrivial to get decent performance.
This is one of the many things that Core Data will handle for you. - Ben _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
