//獲取單例物件
+(id)sharedinstance
return cr;
}-(id)init
return self; }
-(void)initdatabase
nsstring *sql = [nsstring stringwithformat:@"create table if not exists chatlist ("
" id integer primary key autoincrement not null, "
" fromuser text, "
" content text, "
" touser text,"
" fromuserhead text,"
" touserhead text"
");" ];
bool b = [_database executeupdate:sql];
nslog(@"create b = %d",b); }
-(void)initdatabasewithfromuser:(nsstring *)fromuser withtouser:(nsstring *)touser
nsstring *sql = [nsstring stringwithformat:@"create table if not exists _%@and%@ ("
" id integer primary key autoincrement not null, "
" fromuser text, "
" content text, "
" touser text,"
" isread text"
");",fromuser,touser];
bool b = [_database executeupdate:sql];
// nsstring *sql1 = @"create table if not exists receive ("
// " id integer primary key autoincrement not null, "
// " uphone varchar(128), "
// " content varchar(2048), "
// " tphone varchar(32),"
// " ptime varchar(1024),"
// " from_user_name varchar(1024),"
// " from_user_picurl varchar(1024)"
// ");";
nslog(@"create table = %d",b); }
//新增記錄
-(bool)addrecordwithcontent:(nsdictionary *)dict withfromuser:(nsstring *)fromuser withtouser:(nsstring *)touser
//檢視某個記錄是否存在
-(bool)i***istsrecordwithuphone:(nsstring *)uphone andtphone:(nsstring *)tphone
return count>0;
}//獲取聊天列表
-(nsmutablearray *)getchatlist
return array;
}//插入聊天列表
-(void)addchatlist:(nsdictionary *)dict withfromuser:(nsstring *)fromuser
//查詢是否有該聊天記錄
-(bool)ischatfromuser:(nsstring *)fromuser withtouser:(nsstring *)touser
return count>0;
}//修改資訊已讀
-(void)setchatisreadfromuser:(nsstring *)fromuser withtouser:(nsstring *)touser
//獲取某個好友聊天的記錄
-(nsmutablearray *)getrecordwithname:(nsstring *)name
return array;
}//獲取我的聊天記錄
-(nsmutablearray *)getrecordfromuser:(nsstring *)fromuser withtouser:(nsstring *)touser andmaxid:(nsstring *)maxid
nslog(@"array = %@",array);
return array;
}//檢視未讀訊息數
-(nsstring *)getnoreadcount:(nsstring *)fromuser withtouser:(nsstring *)touser
return count;
}
FMDB資料庫總結
這是本人自己整理的fmdb,如有問題請見諒並指出,謝謝!要用fmdb快取,首先要熟練使用sqlite指令,可以參考我的部落格文 下面是我寫的乙個小demo fmdb資料庫最常用的就是增刪改查,下面的demo主要是快取了從網上請求下來的一些和其對應的標題。可以滿足在斷網或再次執行應用的情況下介面有資料...
FMDB資料庫(二)
初識fmdb ios中原生的sqlite api在進行資料儲存的時候,需要使用c語言中的函式,操作比較麻煩。於是,就出現了一系列將sqlite api進行封裝的庫,例如fmdb plausibledatabase sqlitepersistentobjects等。fmdb是一款簡潔 易用的封裝庫。因...
資料庫的操作(使用FMDB)
ios中原生的sqlite api在使用上相當不友好,在使用時,非常不便。於是,就出現了一系列將sqlite api進行封裝的庫,例如fmdb plausibledatabase sqlitepersistentobjects等,fmdb 是一款簡潔 易用的封裝庫,這一篇文章簡單介紹下fmdb的使用...