gpt4 book ai didi

ios - sqlite方法有什么问题

转载 作者:行者123 更新时间:2023-11-28 22:52:58 25 4
gpt4 key购买 nike

这是我尝试使用的方法:

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 个查询在我看来是正确的,但最后一个查询没有插入任何行。第二个,得到一行,所以最后一个应该可以工作(如果我直接使用它就可以)。你觉得哪里不对?

最佳答案

在您的代码中:

const char *sql2 = "insert into orari (orario,idmedicina,presa,forever) values (datetime('?','+1 day'),?,0,1)";

你在 ? 两边加上引号(哪里说 values (datetime('?') 把它改成 values (datetime(?) .生成的代码应如下所示:

const char *sql2 = "insert into orari (orario,idmedicina,presa,forever) values (datetime(?,'+1 day'),?,0,1)";

关于ios - sqlite方法有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11482545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com