-(IBAction)btnAddToFavorite:(id)sender
{
[self insertDataToFavourites:[[tempDict objectForKey:@"pageid"]intValue]:[tempDict objectForKey:@"desc"]];
}
-(void)insertDataToFavourites:(int)pageid :(NSString *)description
{
sqlite3_stmt *insertStatement = nil;
NSString *sql;
int returnvalue;
sql = [NSString stringWithFormat:@"insert into AddFavorite (Id,Description) VALUES (?,?)"];
returnvalue = sqlite3_prepare_v2(database, [sql UTF8String], -1, &insertStatement, NULL);
NSLog(@"\nFavorite ID is:--> %d &\nDescription is:--> %@",[[tempDict valueForKey:@"pageid"] intValue] ,[tempDict valueForKey:@"desc"]);
if (returnvalue == 1){
NSAssert1 (0,@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_text(insertStatement, 1,[[tempDict objectForKey:@"pageid"] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertStatement, 2,[[tempDict objectForKey:@"desc"] UTF8String], -1, SQLITE_TRANSIENT);
if (SQLITE_DONE != sqlite3_step(insertStatement)){
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
}
else{
sqlite3_reset(insertStatement);
}
sqlite3_finalize(insertStatement);
}
这是将数据插入数据库的代码。当我使用选择查询检查数据库时,它显示这样的数据。
谁能告诉我错误在哪里?
谢谢。