C string from SQLite DB encoding type

Discussion in 'iOS Programming' started by RossOliver, Aug 9, 2008.

  1. RossOliver macrumors regular

    Joined:
    Nov 6, 2006
    #1
    Hey,

    I have an SQLite database with a column that may contain words such as café. At the minute I get the text from the database into an NSString using:

    Code:
    NSString *text = [NSString stringWithUTF8String:( char * )sqlite3_column_text( statement, 0 )];
    
    If I then go on to use the NSString, it appears as "cafe?" instead of "café". I don't understand character encodings - is it as simple as using a different method for the NSString, such as stringWithCString:encoding:? What kind of encoding do I need?

    Thanks your time,

    -Ross
     
  2. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #2
    It depends on what encoding you stuck it into the database with. If you got it from a textfield on your Mac then it's probably MacRoman. Unless you've set the default encoding for your computer to something else. If you put it in with some other utility it might be UTF8. If it came from a Windows machine it could be ISO-Latin1.
     
  3. RossOliver thread starter macrumors regular

    Joined:
    Nov 6, 2006
    #3
    I created the database in a plain .txt file and used the pre-installed sqlite command utility in Leopard to .import the text file into the database... is there a default format sqlite would use? or would it be defined from the .txt file?

    -Ross
     
  4. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #4
    It would be set, but not defined, by whatever you created the text file with. Odds are unless you've changed your computers default encoding, or used some program to create the text file that does things quite differently then it's MacRoman. If you used XCode to create the text file XCode writes UTF8 text files by default.
     

Share This Page