我有一个名为FINALORDER
的db表,它填充了一些数据,然后显示在tableview中。当用户点击alertview时从sqlite数据库中删除一条记录
我插入了didSelectRowAtIndexPath
内的alertview
..
alert=[[UIAlertView alloc]initWithTitle:@"Cancel Order" message:@"Do you want to cancel the order" delegate:self cancelButtonTitle:@"dismiss" otherButtonTitles:@"Ok",nil];
[alert show];
[alert release];
和委托方法如下:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if(buttonIndex==1)
{
NSString *deleteSQL = @"DELETE FROM FINALORDER WHERE itemname=?";
if (sqlite3_prepare_v2(database, [deleteSQL UTF8String], -1, &statement, NULL) != SQLITE_OK)
NSLog(@"%s error preparing %s", __FUNCTION__, sqlite3_errmsg(database));
if (sqlite3_bind_text(statement, 1, [itemname UTF8String], -1, NULL) != SQLITE_OK)
NSLog(@"%s error binding %s", __FUNCTION__, sqlite3_errmsg(database));
if (sqlite3_step(statement) != SQLITE_DONE)
NSLog(@"%s error executing %s", __FUNCTION__, sqlite3_errmsg(database));
if (sqlite3_finalize(statement) != SQLITE_OK)
NSLog(@"%s error finalizing %s", __FUNCTION__, sqlite3_errmsg(database));
}
}
我怎么得到它可以在取代项目名称问号的地方?请注意,我的数据库包含以下字段itemname,quantity,totalcost
你为什么不使用CoreData?你知道这是一个下面的SQLight数据库。它使用起来也更容易,并且最终编写的代码更少以管理数据。 – AppHandwerker
我已经在诅咒自己了.. ..但是,我已经走了很远,我的项目回头看起来似乎不是一个选项.. :-( – BoredToDeath
我会争辩说,它总是一个选项,它会让你生活在从长远来看,这是非常容易的,至少你已经定义了数据模型,所以在CoreData中实现它应该是一件轻而易举的事情,这里有很多示例供你跟随,以及来自Apple的一些很好的示例代码 – AppHandwerker