这是我正在尝试使用的方法:
NSString *orario = [NSString new];
int idmed = 0;
fileMgr = [NSFileManager defaultManager];
sqlite3_stmt *stmt=nil;
sqlite3_stmt *stmt1=nil;
sqlite3_stmt *stmt2=nil;
sqlite3 *dbase;
NSString *database = [self.GetDocumentDirectory stringByAppendingPathComponent:@"med.sqlite"];
sqlite3_open([database UTF8String], &dbase);
const char *sql = "delete from orari where date(orario) <= date('now','-2 day','localtime')";
sqlite3_prepare_v2(dbase, sql, -1, &stmt, NULL);
sqlite3_step(stmt);
const char *sql1 = "select orario,idmedicina from orari where date(orario)=date('now','localtime') and forever = 1";
const char *sql2 = "insert into orari (orario,idmedicina,presa,forever) values (datetime('?','+1 day'),?,0,1)";
sqlite3_prepare_v2(dbase, sql1, -1, &stmt1, NULL);
while(sqlite3_step(stmt1) == SQLITE_ROW) {
orario = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt1, 0)];
idmed = [[NSNumber numberWithInt:(int)sqlite3_column_int(stmt1, 1)] intValue];
sqlite3_prepare_v2(dbase, sql2, -1, &stmt2, NULL);
sqlite3_bind_text(stmt2, 1, [orario UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt2, 2, idmed);
sqlite3_step(stmt2);
}
sqlite3_close(dbase);
3 个查询在我看来是正确的,但最后一个没有插入任何行。第二个,得到一排,所以最后一个应该可以工作(如果我直接使用它就可以)。你觉得哪里不对?