iOS開發 FMDB的使用

2021-07-10 19:54:23 字數 1199 閱讀 5805

//獲取沙盒路徑

nsarray *filepath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);

nsstring *documentpath = [filepath objectatindex:0];

nslog(@"filepath:%@",filepath);

//建立資料庫

fmdatabase *database = [fmdatabase databasewithpath:dbfilepath];

//建表

//判斷資料庫是否已經開啟,如果沒有開啟,提示失敗

if (![self.database open])

//為資料庫設定快取,提高查詢效率

[self.database setshouldcachestatements:yes];

//判斷資料庫中是否已經存在這個表,如果不存在則建立該錶

bool result=[self.database executeupdate:@"create table if not exists condition (condition_id integer primary key autoincrement, name text not null);"];

if (result) else

[self getdatabasearray];

[self.database close];

//新增

if ([self.database open]) else

[self.databasearray addobject:@"交通"];

[self.databasearray addobject:@"教育"];

[self.database close];

}//查詢

if ([self.database open])

[self.database close];

}//刪除

if ([self.database open]) else

[self.database close];

}//修改

if ([self.database open]) else

[self.database close];

}

iOS開發 FMDB使用

demo位址 nslog path database fmdatabase alloc initwithpath path id欄位為自增欄位 name char 256位 age char 3位 char 2位 phone char 13位 address char 100位的 if databa...

在iOS開發中使用FMDB

sqlite 是乙個輕量級的關聯式資料庫。ios sdk很早就支援了sqlite,在使用時,只需要加入 libsqlite3.dylib 依賴以及引入 sqlite3.h 標頭檔案即可。但是,原生的sqlite api在使用上相當不友好,在使用時,非常不便。於是,開源社群中就出現了一系列將sqlit...

在iOS開發中使用FMDB

sqlite 是乙個輕量級的關聯式資料庫。ios sdk很早就支援了sqlite,在使用時,只需要加入 libsqlite3.dylib 依賴以及引入 sqlite3.h 標頭檔案即可。但是,原生的sqlite api在使用上相當不友好,在使用時,非常不便。於是,開源社群中就出現了一系列將sqlit...