计数返回参数计数并且是好的。但是索引返回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"));
答案 0 :(得分:3)
来自fine manual:
int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
返回给定名称的SQL参数的索引。
对于parameters:
未跟随数字的问号会创建一个参数,其数字大于已分配的最大参数编号 ...
:AAAA
后跟标识符名称的冒号包含命名参数的位置,其中名称:AAAA 。
在第二部分强调我的。
您的SQL根本没有任何命名参数,您只需要使用普通的旧占位符。参数名称是占位符的名称(:AAAA
),而不是相关列的名称;请记住,您可以在没有名称可以自动派生的地方使用占位符,因此您必须自己命名。
如果您想使用ActiveLevel
作为命名参数,那么您的SQL应如下所示:
update User set Name = ? , Dev = ?, ActiveLevel = :ActiveLevel Where _id = ?
您可能希望用命名参数替换其他占位符(?
)以保持一致性。