This is the method I’m trying to use:
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);
The 3 queries seem to me to be correct, but the last one does not insert any row.
The second one, gets one row, so the last one should work (and it does if I use it directly).
What do you think is wrong?
In your code here:
you put quotes around your
?(Where is saysvalues (datetime('?'change it tovalues (datetime(?).The resulting code should look like this: