在sqlite数据库中删除 [英] deletion in sqlite database

查看:101
本文介绍了在sqlite数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-(BOOL) deletedata:(NSString*)name
{
    const char *dbpath = [databasePath UTF8String];
    if (sqlite3_open(dbpath, &database) == SQLITE_OK)
    {
        sqlite3_stmt *deletestmt;
        NSString *sql_str = [NSString stringWithFormat:@"delete from studentsDetail1 where name=\"%@\"",name];
        const char *sql = [sql_str UTF8String];
        int retVal;
        if ((retVal = sqlite3_prepare_v2(database, sql, -1, &deletestmt, NULL)) == SQLITE_OK) {
            int result;
            if ((result =sqlite3_step(deletestmt)) != SQLITE_DONE) {
                NSLog(@"Failed to execute the query %d",result);
            }
            else {
                NSLog(@"Succesfully Deleted Row");
            }
            sqlite3_finalize(deletestmt);
        }
        else {
            NSLog(@ "Error in preparing Delete statement %d",retVal);
        }
        int result1 = sqlite3_close(database);
        if (result1 != SQLITE_OK){
            NSLog(@"Failure in closing connection to database. Result %d",result1);
        }
        else {

            NSLog(@"Successfully closed DB connection") ;
        }
    }
    return YES;
}







错误来自:
未能成功执行查询5.

哪个陈述错误...

请帮帮我...




Error comes as:
Failed to execute the query 5.
which statement is wrong in it...
please help me...

推荐答案

这不是你的陈述错误 - 数据库文件被锁定。 请参阅此处的文档 [ ^ ]

检查是否有其他进程正在尝试访问同一个文件,并且您已关闭任何以前的交易正确
It's not that your statements are wrong - the database file is locked. See the documentation here[^]
Check to see if any other processes are trying to access the same file, and that you've closed off any previous transactions properly


ya ...我在prepare语句之前尝试了sqlite3_reset()。它现在有效:)
ya... I tried to sqlite3_reset() before the prepare statement. It works now :)


数据库被锁定。看看每个错误代码的含义,所以你可以自己看看。

#define SQLITE_BUSY 5 / *数据库文件被锁定* /



在open()块(最后一行)结束后调用sqlite3_reset()。
The database is locked. Look at the meaning of each error code, so you can see it yourself.
#define SQLITE_BUSY 5 /* The database file is locked */

Call sqlite3_reset() also AFTER the end of the open() block (last line).


这篇关于在sqlite数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆