GreenDao 3 0 學習筆記(二)

2021-08-17 12:24:17 字數 955 閱讀 9178

查詢:

普通查詢:

querybuilder qb = user.querybuilder();

//id在20到25之間的資料

qb.where(qb.and(userinfodao.properties

.id.gt(20), userinfodao.properties

.id.lt(25)));

list users = qb.list();

可用的方法:

-eq():==

-noteq():!=

-gt(): >

-lt():<

-ge:>=

-le:

<=

-like():包含

-between:倆者之間

-in:在某個值內

-notin:不在某個值內

-limit(int): 限制查詢的數量;

-offset(int): 每次返回的數量; offset不能單獨使用;

在同乙個session中如果乙個entities已經被session記錄那麼下一次再次操作該實體時,greendao會先從記憶體中查詢,如果記憶體中沒有再去資料庫中查詢。這樣一方面就極大的提高greendao的查詢效率,另一方面也是需要特別注意的是當entities更新過 greendao仍然會從記憶體中取出舊值,所以如果entities更新過,需要去呼叫daoseesion.clear()方法清除快取後才能查到最新值,否則查詢到的將還是儲存在記憶體中的值。

//清除所所有的快取

daosession.clear();

//清除指定dao類的快取

projectdao = daosession.getnotedao();

projectdao.detachall();

(二)GreenDao3 0的資料庫公升級

public class migrationhelper 生成臨時表,儲存舊的表資料 param db param daoclasses private static void generatetemptables database db,class daoclasses 檢測table是否存在 p...

GreenDao3 0公升級資料庫

看了好幾篇文章,最後還是自己搞明白的,唉,長話短說 greendao我們首先先建立乙個只有乙個成員變數name的student實體類來進行測試.然後需要注意的是不能再使用daomaster裡的newdevsession context,string 來得到daosession物件了,因為這樣做,我們...

c 學習筆記(30)

常用集合演算法 演算法簡介 set intersection 求兩個容器的交集 set union 求兩個容器的並集 set difference 求兩個容器的差集 set intersection 函式原型 set intersection iterator beg1,iterator end1,...