日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

使用SQLite数据库存储数据(4)删除数据记录

發(fā)布時(shí)間:2023/12/13 综合教程 19 生活家
生活随笔 收集整理的這篇文章主要介紹了 使用SQLite数据库存储数据(4)删除数据记录 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

刪除數(shù)據(jù)記錄

當(dāng)從UITableView中刪除一行記錄時(shí),將調(diào)用commitEditingStyle方法。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Get the object to delete from the array
NotebookInfo *notebookInfo = [noteArray objectAtIndex:indexPath.row];
[self removeNotebook: notebookInfo];

// Delete the object from the table
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}

- (void)removeNotebook:(NotebookInfo *)notebookInfo {
// Delete it from the database
sqlite3_stmt *statement;

const char *sql = "delete from Notebook where id = ?";
// 編譯SQL 語句,創(chuàng)建Statement 對(duì)象
if(sqlite3_prepare_v2(noteDB, sql, -1, &statement, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(noteDB));

//When binding parameters, index starts from 1 and not zero.
sqlite3_bind_int(statement, 1, notebookInfo.pk_id);

// SQLITE_DONE 表示成功執(zhí)行了Statement
if (sqlite3_step(statement) != SQLITE_DONE)
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(noteDB));

// Reset a prepared Statement object
sqlite3_reset(statement);
// Destroy the Statement object
sqlite3_finalize(statement);

// Remove it from the array
[noteArray removeObject:notebookInfo];
}

在上面的代碼中,我們實(shí)現(xiàn)了從3個(gè)地方刪除對(duì)應(yīng)的數(shù)據(jù)記錄:
(1) 從SQLite數(shù)據(jù)表中刪除對(duì)應(yīng)的記錄;
(2) 從noteArray 數(shù)組中刪除對(duì)應(yīng)的notebookInfo對(duì)象元素;
(3) 從UITableView 中刪除對(duì)一個(gè)的數(shù)據(jù)行;

現(xiàn)在運(yùn)行App測(cè)試一下,如果代碼運(yùn)行正常,運(yùn)行效果如下圖所示:

一起學(xué)習(xí)GIS及其二次開發(fā),一起進(jìn)步!

總結(jié)

以上是生活随笔為你收集整理的使用SQLite数据库存储数据(4)删除数据记录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。