iOS 資料庫sqlite的使用

2021-07-04 12:58:20 字數 1187 閱讀 5634

.資料庫的增刪查改的方法

sqlite3_exec(db, [sql utf8string], null, null, &erro);

資料庫的使用

步驟:01.匯入框架

02.建立資料庫(sqlite3_exec)並開啟資料庫(sqlite3_open())

03.建立表,新增字段(sqlite3_exec)

04.實現資料庫的增,刪,改,查詢操作(sqlite3_exec)

05.關閉資料庫(sqlite3_close())

查詢操作步驟:

01.校驗語句是否合法:sqlite3_prepare_v2

02.繫結要查詢的資料:sqlite3_bind_text

03.迴圈查詢內容(根據行):sqlite3_step

04.取出這一行裡面的資料(根據對應的類):sqlite3_column_text

.sql語句使用的公式

建表:01. creat table 表名(欄位名

字段型別,欄位名

字段型別)

02. creat table if not exist 表名(欄位名

字段型別,欄位名

字段型別)

列如:creat table if not exist user(id integer,name text,phone text);

插入:insert into 表名(字段,字段)values (『內容』,『內容』);

刪除:delete from 表名 where 字段 = 『要刪的內容』;

修改:update 表名 set 字段 = '修改的內容' where 字段 = '修改前的內容'

set後面是新的資料,where後面是之前的資料

查詢:

01.select *from 表名

查詢所有的字段(*表示所有);

02.select 欄位1,欄位2....from 表名;

如:select *from user;

條件語句:

where 字段 = 內容;

where 字段 is 內容;//相當=

where 字段

!= 內容;

where 字段 is not 內容;

where 字段 > 內容;

where 字段 > 內容 and 字段》內容;&& where 字段 > 內容 or 字段 > 內容

iOS資料庫使用(sqlite3)

資料庫也是資料持久化的一種,但是不同於plist檔案。在ios中 使用資料庫重要的方法 1 開啟資料庫 sqlite3 open 2 建表,修改,新增,更新,刪除資料 sqlite3 exec 3 查詢 校驗語句是否合法 sqlite3 prepare v2 繫結要查詢的資料個sql語句 sqlit...

Sqlite資料庫的使用

以上表的操作為 cn.execute str sqlstring 表的查詢 str sqlstring select from testtable where testcol02 hello limit 1440 offset 2880 where 後面是條件 limit 後面是限制顯示1440條 ...

ios開發中如何使用sqlite資料庫

首先,使用sqlite儲存資料,需要新增libsqlite3.dylib 這個動態庫,然後 新增動態庫的主標頭檔案 import db就是資料庫的象徵,如果要進行crud 增刪改查 得操作db這個例項 property nonatomic,assign sqlite3 db 第一步 開啟資料庫。當系...