Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MontyClift

macrumors newbie
Original poster
Sep 2, 2008
18
0
Hi All,

Is there a way to use symbols like ® in SQLite and the iPhone SDK?
If I do a .read "myfile.sql" that imports data to a table and some of that data contains the ® symbol it goes in fine. However when querying in Terminal>SQLite it shows up as ?
And then in the NSString I create from the field I get no value
Anyone any ideas?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
sqlite uses utf-8 so make sure your strings going into it are in that encoding and that when you get a string from sqlite you create it with that encoding.
 

MontyClift

macrumors newbie
Original poster
Sep 2, 2008
18
0
When I retrieve the value from the database I am creating it with
Code:
[NSString stringWithUTF8String]
so I presume that should take care of the extraction side of it?
When I am inserting it to the database it is coming from a .sql file for example with
Code:
Insert into MyTable(Field1)values('a');
Insert into MyTable(Field1)values('b');
Insert into MyTable(Field1)values('®');
The only values I am having issues with are where I use ®
Are you saying the encoding of the .sql file itself may be wrong? Is there a way to check/change that? Sorry if thats a stupid question but never done this before.

I could just use (R) or do a string replace in the objective c code to get around it but I'd like to know how to do this properly.

Thanks
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
When I retrieve the value from the database I am creating it with
Code:
[NSString stringWithUTF8String]
so I presume that should take care of the extraction side of it?
When I am inserting it to the database it is coming from a .sql file for example with
Code:
Insert into MyTable(Field1)values('a');
Insert into MyTable(Field1)values('b');
Insert into MyTable(Field1)values('®');
The only values I am having issues with are where I use ®
Are you saying the encoding of the .sql file itself may be wrong? Is there a way to check/change that? Sorry if thats a stupid question but never done this before.

I could just use (R) or do a string replace in the objective c code to get around it but I'd like to know how to do this properly.

Thanks

Yes, it's the encoding of the text in the sql file that's the problem. It's apparently not UTF8. Since most Mac text editors default to MacRoman, that's probably what it is.

If the text file was created with something other than a text editor then it might be some other encoding and you'll have to test it.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
The Xcode editor supports different encodings. I also use TextWrangler, which is arguably a little easier for this. Open the file in one of those editors. In Xcode open a Get Info window for the file (you might need to add it to a project). In the info window it tells you what encoding it thinks the file is and you can change the encoding to something else or tell it to reinterpret the file as another encoding.

TextWrangler shows what encoding it thinks the file is at the bottom of the window. There's a menu item 'ReOpen using encoding' which will make the app reinterpret the file as another encoding.

You need the file to be in utf-8.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.