Click here to Skip to main content
11,703,617 members (68,836 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: iPhone Objective-C iOS
-(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 20-Jun-13 0:55am
Edited 20-Jun-13 2:04am
Johnny J.131.2K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

ya... I tried to sqlite3_reset() before the prepare statement. It works now Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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).
  Permalink  

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

  Print Answers RSS
0 Maciej Los 570
1 OriginalGriff 500
2 Sergey Alexandrovich Kryukov 410
3 F-ES Sitecore 165
4 Andy Lanng 159
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 1 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100