inserting html string into sqlite db using objective c

前端 未结 1 1356
说谎
说谎 2021-01-28 18:38

I am using the below snippet to insert html string into sqlite db, my code works fine but when i retrieve the same html string and display in web view it doesn\'t render, some d

相关标签:
1条回答
  • 2021-01-28 19:06

    The single quotes are likely causing the issue. Since it's HTML you can replace the single quotes with an & apos; or you can "double" the single quote like shown here so that sqlite is okay with it:

        NSString *artdetails = [tuser objectForKey:@"art_details"];
        NSString *arttitle = [tuser objectForKey:@"art_title"];
    
        NSString *ad = [artdetails stringByReplacingOccurrencesOfString:@"'" withString:@"''"];    
        NSString *at = [arttitle stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
    

    ...

        sqlite3_bind_text(addStmt, 3, [at UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(addStmt, 4, [ad UTF8String], -1, SQLITE_TRANSIENT);
    

    etc

    0 讨论(0)
提交回复
热议问题