i am beginner in iphone application and want to d开发者_开发问答elete record from database is it supported by sqlite3 and yes then how to perform this operation.
Yes it is supported.
Here is the reference for how to use it.
Here is an example function that delete an item from sqlite database with given url. Here we have table "ARTICLES" and column "GUID".
for example if we will write query like this
DELETE FROM ARTICLES WHERE GUID ='http://www.google.com'
it mean we will delete row where value in column "GUID" is equals to "http://www.google.com" the whole row will be deleted
- (void) DeleteFromDataBase: (NSString*) mainUrl
{
sqlite3_stmt* statement;
if( sqlite3_open([self.dataBasePath UTF8String], &articlesDB) == SQLITE_OK )
{
// Create Query String.
NSString* sqlStatement = [NSString stringWithFormat:@"DELETE FROM ARTICLES WHERE GUID ='%@'", mainUrl];
if( sqlite3_prepare_v2(articlesDB, [sqlStatement UTF8String], -1, &statement, NULL) == SQLITE_OK )
{
if( sqlite3_step(statement) == SQLITE_DONE )
{
NSLog( @"Item with url: %@ was deleted", mainUrl );
}
else
{
NSLog( @"DeleteFromDataBase: Failed from sqlite3_step. Error is: %s", sqlite3_errmsg(articlesDB) );
}
}
else
{
NSLog( @"DeleteFromDataBase: Failed from sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(articlesDB) );
}
// Finalize and close database.
sqlite3_finalize(statement);
sqlite3_close(articlesDB);
}
else
{
NSLog( @"DeleteFromDataBase: Error While opening database. Error: %s\n", sqlite3_errmsg(articlesDB) );
}
}
精彩评论