objective c - Single quote encoding issue reading from sqlite for iPhone -
i have created sqlite db iphone store data (strings). have data contains ' single quotes (i.e. don't tense). inserted db using normal '' escape sqlite.
insert todo(test) values('don''t tense');
when select on data in terminal can see single quote in record.
don't tense
my problem when read record in, single quote not there in nslog:
dont tense
this call read in field:
self.text = [nsstring stringwithutf8string:(char *)sqlite3_column_text(init_statement, 1)]; nslog(@"%@",self.translation);
i appreciate on how ensure quote read in.
below full code, if helps:
static sqlite3_stmt *init_statement = nil; @implementation todo @synthesize primarykey,text; - (id)initwithprimarykey:(nsinteger)pk database:(sqlite3 *)db { if (self = [super init]) { primarykey = pk; database = db; // compile query retrieving book data. see insertnewbookintodatabase: more detail. if (init_statement == nil) { // note '?' @ end of query. parameter can replaced bound variable. // great way optimize because used queries can compiled once, each // use new variable values can bound placeholders. const char *sql = "select text todo pk=?"; if (sqlite3_prepare_v2(database, sql, -1, &init_statement, null) != sqlite_ok) { nsassert1(0, @"error: failed prepare statement message '%s'.", sqlite3_errmsg(database)); } } // query, bind primary key first (and only) placeholder in statement. // note parameters numbered 1, not 0. sqlite3_bind_int(init_statement, 1, primarykey); if (sqlite3_step(init_statement) == sqlite_row) { self.text = [nsstring stringwithutf8string:(char *)sqlite3_column_text(init_statement, 0)]; nslog(@"%@",self.text); } else { self.text = @"nothing"; } // reset statement future reuse. sqlite3_reset(init_statement); } return self; }
i fixed it. seems when updating database didn't delete old 1 off simulator testing old data entire time. stupid mistake! there no issue reading in single quotes sqlite (probably why never find information it). read , tried help!
Comments
Post a Comment