由于db中无法识别的令牌,无法在sqlite数据库中插入?

时间:2022-09-24 15:43:06
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);
}

Query Actual Result:

查询实际结果:

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

)

i am not able to insert using above query because it is contains special character in sqlite database telling UnRecognized token .

我无法使用上面的查询插入,因为它在sqlite数据库中包含告诉UnRecognized令牌的特殊字符。

1 个解决方案

#1


1  

Try FMDB wrapper it will handle your array object as per its type. also handle special characters, quotes etc...

尝试FMDB包装器,它将根据其类型处理您的数组对象。还处理特殊字符,引号等...

https://github.com/ccgus/fmdb

Search execute update with format method it will work for your query.

使用格式化方法搜索执行更新,它将适用于您的查询。

[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"];
}

#1


1  

Try FMDB wrapper it will handle your array object as per its type. also handle special characters, quotes etc...

尝试FMDB包装器,它将根据其类型处理您的数组对象。还处理特殊字符,引号等...

https://github.com/ccgus/fmdb

Search execute update with format method it will work for your query.

使用格式化方法搜索执行更新,它将适用于您的查询。

[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"];
}