Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Objective-C
-(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;
}



Error comes as:
Failed to execute the query 5.
which statement is wrong in it...
please help me...
Posted
Updated 20-Jun-13 2:04am
v2

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
 
Share this answer
 
ya... I tried to sqlite3_reset() before the prepare statement. It works now :)
 
Share this answer
 
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).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900