-(void)setFlagToZero:(BOOL)flg id:(NSString *)qid
{
NSLog(@"flag %hhd and ID:%@ ",flg,qid);
sqlite3 *database;
quiz = [[NSMutableArray alloc] init];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
const char *sqlStatement = &"UPDATE Question set Question_Flag="+flg+"where question_ID="+qid;
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSString *aQuestion = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
}
}
else
{
NSLog(@"Error occured in connection");
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
@end
显示如下错误
二进制表达式的操作数无效(' char(*)[36]'' char *')
请帮我修正更正的代码。
答案 0 :(得分:1)
问题在于以下声明(您已在该字符串中添加了&
和+
):
const char *sqlStatement = &"UPDATE Question set Question_Flag="+flg+"where question_ID="+qid;
将其更改为:
NSString *query = [NSString stringWithFormat:@"UPDATE Question set Question_Flag=%d where question_ID=%d",flg,qid];
const char *sqlStatement = [query UTF8String];
答案 1 :(得分:0)
试试这个更新,它的工作
-(void)updateDataBaseRecords:(NSString *)databaseQuery
{
NSString *replaceStatement = databaseQuery;
// Execute the replace
char *error;
if (sqlite3_exec(database, [replaceStatement UTF8String], NULL, NULL, &error) == SQLITE_OK)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Updated successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ];
[alert show];
}
else
{
NSLog(@"Error: %s", error);
}
}
在此功能中直接传递您的查询