Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Delete Record From SQLite for iPhone

Tags:

iphone

How to Delete all the Record From SQLite Database.

 +(BOOL)deleteFromtbl {
        sqlite3 *database;
        BOOL retValue = YES;
        if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
            const char *sqlStatement = "Delete from tbl";
            sqlite3_stmt *compiledStatement;
            retValue = sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
            sqlite3_finalize(compiledStatement);
        }
        sqlite3_close(database);

        return retValue;        
    }

These code did not work for me.

Thanks in advance.

like image 400
Mobile App Dev Avatar asked Oct 11 '22 16:10

Mobile App Dev


1 Answers

sqlite3_step, this function requires after preparing compile statement.

use in this way

+(BOOL)deleteFromtbl {
        sqlite3 *database;
        BOOL retValue = YES;
        if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
            const char *sqlStatement = "Delete from tbl";
            sqlite3_stmt *compiledStatement;
            retValue = sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
if(SQLITE_DONE != sqlite3_step(compiledStatement))//add this line
    {
        NSLog(@"Error while inserting data. '%s'", sqlite3_errmsg(database));
        return NO;
    }
            sqlite3_finalize(compiledStatement);
        }
        sqlite3_close(database);

        return retValue;        
    }
like image 185
Ishu Avatar answered Oct 19 '22 00:10

Ishu