开发者

bind or column index out of range

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜