绑定或列索引超出范围
我想删除现有 sqlite 数据库中的所有数据,这是我正在使用的代码:
sqlite3* database;
databaseName = @"AppDB";
NSString *pathToDatabase;
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
pathToDatabase = [documentsDir stringByAppendingPathComponent:databaseName];
int databaseReturnCode = sqlite3_open([pathToDatabase UTF8String], &database);
NSLog(@"databaseReturnCode %d",databaseReturnCode);
if(databaseReturnCode == SQLITE_OK) {
const char *sql = "delete from AppDB";
sqlite3_stmt *delete_statement;
sqlite3_prepare_v2(database, sql, -1, &delete_statement, NULL);
sqlite3_bind_int(delete_statement, 1, 1);
printf( "error or not an error? : %s\n", sqlite3_errmsg(database) );
sqlite3_reset(delete_statement);
sqlite3_finalize(delete_statement);
}
sqlite3_close(database);
该数据库中有多个字段和多个表。请让我知道错误是什么。提前致谢。
I want to delete all data in an existing sqlite DB, this is the code i am using:
sqlite3* database;
databaseName = @"AppDB";
NSString *pathToDatabase;
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
pathToDatabase = [documentsDir stringByAppendingPathComponent:databaseName];
int databaseReturnCode = sqlite3_open([pathToDatabase UTF8String], &database);
NSLog(@"databaseReturnCode %d",databaseReturnCode);
if(databaseReturnCode == SQLITE_OK) {
const char *sql = "delete from AppDB";
sqlite3_stmt *delete_statement;
sqlite3_prepare_v2(database, sql, -1, &delete_statement, NULL);
sqlite3_bind_int(delete_statement, 1, 1);
printf( "error or not an error? : %s\n", sqlite3_errmsg(database) );
sqlite3_reset(delete_statement);
sqlite3_finalize(delete_statement);
}
sqlite3_close(database);
there are more than one field and more than one table in this DB. Please let me know what the error is. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注释此
sqlite3_bind_int(delete_statement, 1, 1);
行并运行代码,因为在查询中您没有任何需要绑定的参数。我也想知道这个查询是否存在?你能直接从某个数据库中删除吗?我认为没有任何查询需要数据库名称! (我希望 AppDB 是表名)。[我们应该遵循标准命名约定以便于理解。]
谢谢
Please comment this
sqlite3_bind_int(delete_statement, 1, 1);
line and run the code, Because in query you do not have any parameter which will need binding. Also I wander does this query exists? can you do like this delete from someDatabase directly? I don't think there is any query which takes database name! (I hopeAppDB
is table name).[We should follow standard naming conventions for easy understanding.]
Thanks