我正在尝试将我的数据插入到成功创建的 db.db 中,但数据没有插入到数据库中。但是在显示错误之后数据成功进入 insertsql。请检查我的代码
-(void)insertDB
{
NSString *dname=[[NSString alloc]init];
dname=[delegate.Name objectAtIndex:0];
sqlite3_stmt *statement;
const char *dbpath=[delegate.databasepath UTF8String];
if (sqlite3_open(dbpath, &contactDB)==SQLITE_OK)
{
NSString *insertSQL=[NSString stringWithFormat:@"INSERT INTO STABLE (NAME) VALUES (\"%@\")",dname];
//insert sql is ok,after that they shows error
const char *insert_stmt=[insertSQL UTF8String];
NSLog(@"const char%@",insert_stmt);
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement,NULL);
if (sqlite3_step(statement)==SQLITE_DONE)
{
NSLog(@"saved");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"data" message:@"saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[self counting];
}
else
{
NSLog(@"Failed to add new favourites");
NSLog(@"Failed to update row %s", sqlite3_errmsg(contactDB));
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
[self loadmusic];
}