cocoa - Application crashing due to unicode characters in string -
i making application in have store data remote db local sqlite3 db.
problem - when string inserted contains unicode character such as: \u00a0 or \u2022 or \u2019, crashes.
the part of code crashes this-
nsstring *insertquery = @"insert xyz(field1,field2) values (@"1",[recorddict objectforkey:@"field2"]); // recorddict contains value: @"\u00a0 \u00a0 \u00a0 \u00a0the cadfsdfsdfptain\u2019s" key: @"field2" sqlite3_stmt *insertstmnt; const char *sql = [insertquery cstringusingencoding:1]; printf("insertquery - %s",sql); // showing insertquery - (null) , crashing @ next line if(sqlite3_prepare_v2(database, sql, -1, &insertstmnt, null) != sqlite_ok){ nslog(@"error while creating insert statement. '%s'",sqlite3_errmsg(database)); }
can suggest me how resolve problem?
thanks,
miraaj
cstringusingencoding:
returns null
when string cannot losslessly converted specified encoding, hence crash. can use canbeconvertedtoencoding:
ensure conversion possible.
furthermore, value 1
corresponds nsasciistringencoding
fail string unicode characters. nsutf8stringencoding
might more appropriate.
Comments
Post a Comment