我正在调用此函数并首先删除所有数据,然后在其中插入更新的值。但有些如何从database.it中删除所有表格总是从代码中显示alertview
。不知道我错了什么。任何帮助都会被赞赏。谢谢..
-(void)fillDate
{
filemgr=[NSFileManager defaultManager];
NSString *querySQL = @"delete from getdate";
const char *dbpath = [[appDelegate getDBPath] UTF8String];
//NSLog(@"path= %@",dbpath);
BOOL flag=FALSE;
if (sqlite3_open(dbpath, &dtdb) == SQLITE_OK)
{
//"open";
const char *query_stmt = [querySQL UTF8String];
sqlite3_prepare_v2(dtdb,query_stmt,-1,&statement,NULL);
if (sqlite3_step(statement)==SQLITE_DONE)
{
//table deleted
flag=TRUE;
}
else
{
UIAlertView *d=[[UIAlertView alloc]initWithTitle:@"Message" message:@"Your Table does not deleted" delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[d show];
flag=FALSE;
}
}
else
{
//"can't open";
}
sqlite3_close(dtdb);
sqlite3_finalize(statement);
if (flag)
{
sqlite3_stmt *stmt;
const char *cdbpath=[[appDelegate getDBPath] UTF8String];
if ((sqlite3_open(cdbpath,&dtdb)==SQLITE_OK))
{
char* errorMessage;
sqlite3_exec(dtdb, "BEGIN TRANSACTION", NULL, NULL, &errorMessage);
char buffer[] = "INSERT INTO getdate(lastdate) VALUES (?1)";
sqlite3_prepare_v2(dtdb, buffer, strlen(buffer), &stmt, NULL);
// for (unsigned i = 0; i < 1; i++)
// {
// NSMutableDictionary *dict=[arrayAllEvents objectAtIndex:i];
//NSLog(@"dict:%@",dict);
sqlite3_bind_text(stmt, 1, [[df stringFromDate:[NSDate date]]UTF8String], -1, SQLITE_STATIC);
int success = sqlite3_step(stmt);
sqlite3_reset(stmt);
if (success != SQLITE_DONE)
{
//nslog(@"error: %s",sqlite3_errmsg(dtdb));
}
//nslog(@"... data created.");
// }///for
if(sqlite3_exec(dtdb, "COMMIT TRANSACTION", NULL, NULL, &errorMessage)==SQLITE_OK)
{
NSLog(@"commited Events");
}
else
{
NSLog(@"Not commited");
}
// sqlite3_exec(dtdb, "COMMIT TRANSACTION", NULL, NULL, &errorMessage);
sqlite3_finalize(stmt);
}//
}
sqlite3_close(dtdb);
}
答案 0 :(得分:2)
如果您已更新数据库,则只需用旧的数据库替换新数据库。删除应用程序并再次运行。你的代码似乎很完美。