我是iphone应用程序的初学者,想要从sqlite3支持从数据库删除记录,是的,然后如何执行此操作。
答案 0 :(得分:1)
是支持。
Here是如何使用它的参考。
答案 1 :(得分:1)
这是一个使用给定url从sqlite数据库中删除项目的示例函数。这里我们有表“ARTICLES”和列“GUID”。
例如,如果我们将编写这样的查询
DELETE FROM ARTICLES WHERE GUID ='http://www.google.com'
这意味着我们将删除“GUID”列中的值等于“http://www.google.com”的行 整行将被删除
- (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) );
}
}