NSString * query = [NSString stringWithFormat:@"insert into tiger_%@ %@ values %@",modulearr[j],Qkey,Qval];
NSLog(@"query:%@",query);
sqlite3_stmt* stmt =NULL;
int rc=0;
rc =sqlite3_prepare_v2(Login, [query UTF8String], -1, &stmt, NULL);
if(rc == SQLITE_OK)
{
rc =sqlite3_step(stmt);
if(rc == SQLITE_DONE) //success
{
rc = SQLITE_OK;
}
sqlite3_finalize(stmt);
}
查询实际结果:
insert into tiger_Campaigns (
actualsalescount,
modifiedby,
"assigned_user_id",
expectedroi,
campaigntype,
actualresponsecount,
numsent,
campaignstatus,
"campaign_no",
actualcost,
actualroi,
expectedresponsecount,
campaignname,
expectedresponse,
"cf_type",
modifiedtime,
id,
"product_id",
targetaudience,
createdtime,
budgetcost,
sponsor,
targetsize,
closingdate,
expectedrevenue,
expectedsalescount,
description
) values (
0,
19x1,
19x1,
"0.00000000",
None,
0,
0,
None,
CAM8,
"0.00000000",
"0.00000000",
0,
"1-31",
None,
None,
"2017-01-03 07:09:02",
1x557,
None,
None,
"2017-01-03 07:09:02",
"0.00000000",
None,
0,
"2017-01-03",
"0.00000000",
0,
None
)
我无法使用上面的查询插入,因为它在sqlite数据库中包含告诉UnRecognized令牌的特殊字符。
答案 0 :(得分:1)
尝试FMDB包装器,它将根据其类型处理您的数组对象。还处理特殊字符,引号等...
使用格式化方法搜索执行更新,它将适用于您的查询。
[DELEGATE.db executeUpdateWithFormat:@"INSERT INTO tbl_name (title, detail, type) VALUES (%@,%@,%@);",
strTitle,
[NSKeyedArchiver archivedDataWithRootObject:self.dictionary],
@"Interest"];
if ([DELEGATE.db hadError]) {
NSLog(@"error %@",[DELEGATE.db lastErrorMessage]);
} else {
[DELEGATE showAlertLabel:@"Calculation Saved"];
}