@@ -102,6 +102,19 @@ public abstract class DbEntity {
|
|||||||
return util.findData(clazz, expression);
|
return util.findData(clazz, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模糊查询一组数据
|
||||||
|
* <code>
|
||||||
|
* DownloadEntity.findDatas(DownloadEntity.class, "downloadUrl like http://");
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @return 没有数据返回null
|
||||||
|
*/
|
||||||
|
public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) {
|
||||||
|
DelegateWrapper util = DelegateWrapper.getInstance();
|
||||||
|
return util.findDataByFuzzy(clazz, conditions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询一行数据
|
* 查询一行数据
|
||||||
* <code>
|
* <code>
|
||||||
|
|||||||
@@ -355,6 +355,26 @@ class DelegateFind extends AbsDelegate {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模糊查寻数据
|
||||||
|
*/
|
||||||
|
<T extends DbEntity> List<T> findDataByFuzzy(SQLiteDatabase db, Class<T> clazz, String conditions) {
|
||||||
|
db = checkDb(db);
|
||||||
|
if(TextUtils.isEmpty(conditions)){
|
||||||
|
throw new IllegalArgumentException("sql语句表达式不能为null或\"\"");
|
||||||
|
}
|
||||||
|
if(!conditions.toUpperCase().contains("LIKE")){
|
||||||
|
throw new IllegalArgumentException("sql语句表达式未包含LIEK");
|
||||||
|
}
|
||||||
|
String sql =
|
||||||
|
"SELECT rowid, * FROM " + CommonUtil.getClassName(clazz) + " WHERE "+conditions;
|
||||||
|
print(FIND_DATA, sql);
|
||||||
|
Cursor cursor = db.rawQuery(sql, null);
|
||||||
|
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
|
||||||
|
closeCursor(cursor);
|
||||||
|
close(db);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查找表的所有数据
|
* 查找表的所有数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -118,6 +118,13 @@ public class DelegateWrapper {
|
|||||||
return mDManager.getDelegate(DelegateFind.class).findData(mDb, clazz, expression);
|
return mDManager.getDelegate(DelegateFind.class).findData(mDb, clazz, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模糊查寻数据
|
||||||
|
*/
|
||||||
|
<T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) {
|
||||||
|
return mDManager.getDelegate(DelegateFind.class).findDataByFuzzy(mDb, clazz, conditions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过rowId判断数据是否存在
|
* 通过rowId判断数据是否存在
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user