• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
re: SQLite3 and Unicode Strings - Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: SQLite3 and Unicode Strings - Problem


  • Subject: re: SQLite3 and Unicode Strings - Problem
  • From: Ben Trumbull <email@hidden>
  • Date: Tue, 7 Apr 2009 17:49:22 -0700

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@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Simple printing hangs
  • Next by Date: Re: Simple printing hangs
  • Previous by thread: SQLite3 and Unicode Strings - Problem
  • Next by thread: QTMovie and playing backwards
  • Index(es):
    • Date
    • Thread