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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With