绑定或列索引超出范围

发布于 2024-11-01 05:21:33 字数 981 浏览 1 评论 0原文

我想删除现有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2024-11-08 05:21:33

请注释此 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 hope AppDB is table name).

[We should follow standard naming conventions for easy understanding.]

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文