sqlite3_bind_parameter_index返回0?
计数返回参数的计数并且很好。然而索引返回 0。 有什么想法吗?
sqlite3 *database;
sqlite3_stmt *updateStmt;
int ID;
const char *sql;
sql = "update User set Name = ? , Dev = ?,ActiveLevel = ? Where _id = ?";
if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
NSLog(@"count %d",sqlite3_bind_parameter_count(updateStmt));
NSLog(@"Index %d",sqlite3_bind_parameter_index(updateStmt,"ActiveLevel"));
The count returns a count of the parameters and is good. However the index is returning 0.
Any ideas?
sqlite3 *database;
sqlite3_stmt *updateStmt;
int ID;
const char *sql;
sql = "update User set Name = ? , Dev = ?,ActiveLevel = ? Where _id = ?";
if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
NSLog(@"count %d",sqlite3_bind_parameter_count(updateStmt));
NSLog(@"Index %d",sqlite3_bind_parameter_index(updateStmt,"ActiveLevel"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自精细手册:
对于参数:
强调我的第二部分。
你的 SQL 根本没有任何命名参数,只有普通的旧占位符。参数名称是占位符的名称 (
:AAAA
),而不是相关列的名称;请记住,您可以在无法自动派生名称的地方使用占位符,因此您必须自己命名它们。如果您想使用
ActiveLevel
作为命名参数,那么您的 SQL 应如下所示:并且您可能希望用命名参数替换其他占位符 (
?
)为了一致性。From the fine manual:
And for parameters:
Emphasis mine in the second section.
Your SQL doesn't have any named parameters at all, you just have plain old placeholders. The parameter name is the name of the placeholder (
:AAAA
), not the name of the column in question; remember that you can use placeholders in places where no name could be automatically derived so you have to name them yourself.If you want to use
ActiveLevel
as a named parameter, then your SQL should look like this:And you'd probably want to replace the other placeholders (
?
) with named parameters for consistency.