Ruchir Shah
Ruchir Shah

Reputation: 896

iphone sqlite3_column_text issue

I have a column in sqlite3 table. Column has values like

1 ½”

1 ¾”

2 ½” etc. Column has VARCHAR datatype.

I am using this code.

pref_HoseDiameter = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; 

Now, when I am fetching these values from database, I am getting pref_HoseDiameter string values like this:

1 1/2"

1 3/4"

2 1/2"

How to fetch those values as they are in database or how to convert them that look like database values.

Help would be appreciated. Thanks in advance.

Upvotes: 1

Views: 1565

Answers (1)

kennytm
kennytm

Reputation: 523314

Try to use sqlite3_column_text16 to get the string as UTF-16, then create the string with +stringWithCharacters:.

const UInt16* text = sqlite3_column_text16(statement, column);
int text_len = // find the first 0x0000 in text;
NSString* str = [NSString stringWithCharacters:text length:text_len];

Upvotes: 2

Related Questions