FMDB的簡單使用

2021-07-09 18:33:04 字數 967 閱讀 2712

fmdb一種oc庫,是對sqlite進行了包裝。源**位址

fmdb中包含三個主要類

1. fmdatabase

代表乙個簡單sqlite資料庫,用來執行sql語句。

2. fmresultset

fmdatabase下執行sql的結果集。

3. fmdatabasequeue

用於多執行緒下「執行緒安全」的資料庫佇列。

建立資料庫

fmdatabase *db =[fmdatabase databasewithpath:@"/tmp/tmp.db"];

如果path為@「」或null,那麼資料庫關閉時,資料庫將刪除。

開啟資料庫

與資料庫互動前需確保資料庫是開啟的。

if (![db open])

開啟時可能會遇到開啟失敗情況,如無足夠資源或無許可權。

執行更新操作

sql語句一般分為兩種:

查詢, select

更新,create、update、insert、alert、commit、begin、detach、delete、drop、end、explain、vacuum、replace…

fmresultset *set = [db executequery:@"select * from mytable"];

while ([set next])

注意:如果資料庫中沒有mytable表,set為nil。

如果mytable表存在但沒有記錄,那麼set不為nil。

如果mytable表中有記錄,只有[set next]一次之後才能取出資料。

fmdb提供很多方法從set中獲取資料。

FMDB的簡單使用

首先,建立乙個類,採用單例模式,對videodatabase進行操作,在.h檔案中,我已經對各個方法的使用做了說明 import import hcvideoinfo.h typedef void hcvideoinfoarray nsarray videolistarray inte ce hcv...

FMDB框架的簡單使用 swift

fmdb框架是oc的,在swift中使用,需要建立乙個橋接檔案轉換 在橋接檔案中匯入fndb的標頭檔案 static let shareinstance sqlitetool 建立和開啟乙個資料庫 如果有就直接開啟,如果沒有,建立乙個再開啟 lazy var db fmdatabase 例項化db物...

FMDB簡單應用

cpp view plain copy 1,拿到資料庫檔案的路徑 self.path nshomedirectory 2,拿到資料庫物件,開啟資料庫,如果這個資料庫不存在,就會自動建立 fmdatabase db fmdatabase databasewithpath path bool res d...