Click here to Skip to main content
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 1:55am
Edited 20-Jun-13 3:04am
Johnny J.115.8K
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 OriginalGriff 341
1 Marcin Kozub 225
2 Praneet Nadkar 197
3 Sergey Alexandrovich Kryukov 190
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 1 Jul 2013
Copyright © CodeProject, 1999-2014
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