iOS SQLite3使用簡介

2021-06-19 20:50:55 字數 1346 閱讀 7080

[摘要]本文介紹ios中sqlite3的使用,包括插入資料、查詢資料等操作,並提供簡單的示例**供參考。

一、在firefox中開啟sqlite3(如果沒有,選擇工具->附加元件,新增即可)新建sqlite3資料庫contacts,建立乙個members表,字段 id,integer,主鍵,自增;name,varchar;email,varchar,null;birthday,datetime,null。

向表中新增一些資料:

3@inte***ce

homeviewcontroller : uiviewcontroller

6- (nsstring

*)filepath;//資料庫檔案的路徑。一般在沙箱的documents裡邊操作

7@end

2. homeviewcontroller.m**:

view row code

1#import "homeviewcontroller.h"23

@inte***ce

homeviewcontroller ()

4@end

5@implementation

homeviewcontroller

6//該方法用於返回資料庫在documents資料夾中的全路徑資訊78

- (nsstring

*)filepath

13//開啟資料庫的方法

1415

- (void)opendb20}

21//插入資料方法

22- (void)insertrecordintotablename:(nsstring

*)tablename

23withfield1:(nsstring

*)field1 field1value:(nsstring

*)field1value

24andfield2:(nsstring

*)field2 field2value:(nsstring

*)field2value

25andfield3:(nsstring

*)field3 field3value:(nsstring

*)field3value

45if (sqlite3_step(statement) !

=sqlite_done)

4950}51

5253

//查詢資料

54- (void)getallcontacts

80sqlite3_finalize(statement);81}

82}83- (void)viewdidload

84100

@end

插入資料後的效果:

ios sqlite3簡單使用

1.匯入sqlite3系統標頭檔案 import2.建立變數sqlite3 3.定義儲存路徑 首先自定義乙個方法,返回我們當前應用程式沙盒目錄 也就是說希望資料庫儲存在 nsstring datafilepath4.建立資料庫 之後在指定位置建立或開啟資料庫 void creatdatabase n...

ios SQLite3 使用命令

在ios下開發使用sqlite,和在windows下使用有一些差別,這裡簡單介紹一些在ios下使用sqlite3的一些簡單的命令 由建立乙個資料庫的乙個表來說 先指定路徑,這裡指定的路徑是桌面,cd desktop 然後 建立資料庫 sqlite3 date1.db databases 顯示所有資料...

iOS sqlite3的使用(増刪改查)

目錄 一 sqlite3常用函式 二 將sqlite3整合到專案,實現増刪改查 三 封裝dbmanager 四 demo 1 sqlite3 open 用來建立和開啟資料庫檔案,接收兩個引數,第乙個是資料庫的名字,第二個是資料庫的控制代碼。如果資料庫檔案不存在,將首先新建它,然後再開啟它,否則只是開...