gpt4 book ai didi

ios - 错误: near "?": syntax error using sqlite and obj-c

转载 作者:行者123 更新时间:2023-12-01 19:22:02 25 4
gpt4 key购买 nike

在此处提出建议后,我尝试绑定(bind)传递到查询中的值,但我不断收到语法错误:错误:靠近“?”:有人可以解释一下为什么吗?

NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:@"banklist" ofType:@"sqlite3"];
if(sqlite3_open([sqLiteDb UTF8String], &_database) == SQLITE_OK)
{
{
// prep statement
sqlite3_stmt *statement;
NSString *querySQL = @"UPDATE ? SET recipe_name=? WHERE cell_id=?";
NSLog(@"query: %@", querySQL);
const char *query_stmt = [querySQL UTF8String];

// preparing a query compiles the query so it can be re-used.
sqlite3_prepare_v2(_database, query_stmt, -1, &statement, NULL);
sqlite3_bind_text(statement, 1, [del.dayName UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_text(statement, 2, [info.name UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_int(statement, 1, del.tableRowNumber);

// process result
if (sqlite3_step(statement) != SQLITE_DONE)
{
NSLog(@"error: %s", sqlite3_errmsg(_database));
}

sqlite3_finalize(statement);
}

{
// prep statement
sqlite3_stmt *statement;
NSString *querySQL = @"UPDATE ? SET recipe_id = (SELECT key FROM recipes WHERE name = ?.recipe_name)";
NSLog(@"query: %@", querySQL);
const char *query_stmt = [querySQL UTF8String];

// preparing a query compiles the query so it can be re-used.
sqlite3_prepare_v2(_database, query_stmt, -1, &statement, NULL);
sqlite3_bind_text(statement, 1, [del.dayName UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_text(statement, 2, [del.dayName UTF8String], -1, SQLITE_STATIC);

// process result
if (sqlite3_step(statement) != SQLITE_DONE)
{
NSLog(@"error: %s", sqlite3_errmsg(_database));
}

sqlite3_finalize(statement);
}
}

sqlite3_close(_database);

最佳答案

您可以将 sqlite3_bind_xxx 用于 SQL 中的值,但不能用于表名称。您必须使用 stringWithFormat 作为表名称,使用 sqlite3_bind_xxx 作为值。

关于ios - 错误: near "?": syntax error using sqlite and obj-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18625006/

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