如何插入包含"的字符串sqlite ios中的字符 [英] How to insert string that contains " character in sqlite ios

查看:53
本文介绍了如何插入包含"的字符串sqlite ios中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码但 sqlite 给我错误

i am using following code but sqlite giving me error

 NSArray* a = [NSArray arrayWithObjects:
              @"\""
              @"\\ \"",
              nil];
quantity=[quantity stringByReplacingOccurrencesOfString:[a objectAtIndex:0 ] withString:[a objectAtIndex:1]];
queryString = [NSString stringWithFormat:@"INSERT INTO SHOPINGLIST (QUANTITY) VALUES (\"%@\")",quantity];

它给出的错误是:-diax1"附近:查询中的语法错误 INSERT INTO SHOPINGLIST原量=1片,中(4-1/2"diax1/8"厚)

it gives error that:- near "diax1": syntax error in query INSERT INTO SHOPINGLIST original quantity is =1 slice,medium(4-1/2"diax1/8"thick)

推荐答案

要在 iOS 中的 SQLite 中插入特殊字符,请使用占位符,例如(另请检查 Sqlite 中允许使用哪些特殊字符):

To insert special characters in SQLite in iOS, use placeholders like (also please check which special characters are allowed in Sqlite):

queryString = @"INSERT INTO SHOPINGLIST (QUANTITY) VALUES (?)";
sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, queryString, -1, &compiledStatement, NULL) == SQLITE_OK) {
        sqlite3_bind_text(compiledStatement, 1, [quantity UTF8String], -1, SQLITE_TRANSIENT);
  // Use sqlite3_bind_text for string values. For other type of values, check sqlite documentation.
 // .... And So on.

    }

这篇关于如何插入包含"的字符串sqlite ios中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆