本文整理汇总了Java中org.litepal.crud.DataSupport.findBySQL方法的典型用法代码示例。如果您正苦于以下问题:Java DataSupport.findBySQL方法的具体用法?Java DataSupport.findBySQL怎么用?Java DataSupport.findBySQL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.litepal.crud.DataSupport
的用法示例。
在下文中一共展示了DataSupport.findBySQL方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCount
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testCount() {
int result = DataSupport.count(Student.class);
int realResult = -100;
Cursor cursor = DataSupport.findBySQL("select count(1) from " + studentTable);
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
result = DataSupport.where("id > ?", "99").count(studentTable);
cursor = DataSupport.findBySQL("select count(1) from " + studentTable + " where id > ?", "99");
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
try {
DataSupport.count("nosuchtable");
fail();
} catch (Exception e) {
}
}
示例2: testAverage
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testAverage() {
double result = DataSupport.average(Student.class, "age");
double realResult = -100;
Cursor cursor = DataSupport.findBySQL("select avg(age) from " + studentTable);
if (cursor.moveToFirst()) {
realResult = cursor.getDouble(0);
}
cursor.close();
assertEquals(realResult, result);
result = DataSupport.where("id > ?", "99").average(studentTable, "age");
cursor = DataSupport.findBySQL("select avg(age) from " + studentTable + " where id > ?", "99");
if (cursor.moveToFirst()) {
realResult = cursor.getDouble(0);
}
cursor.close();
assertEquals(realResult, result);
try {
DataSupport.average(Student.class, "nosuchcolumn");
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: testMax
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testMax() {
int result = DataSupport.max(Student.class, "age", Integer.TYPE);
int realResult = -100;
Cursor cursor = DataSupport.findBySQL("select max(age) from " + studentTable);
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
result = DataSupport.where("age < ?", "20").max(studentTable, "age", Integer.TYPE);
cursor = DataSupport.findBySQL("select max(age) from " + studentTable + " where age < ?", "20");
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
}
示例4: testMin
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testMin() {
int result = DataSupport.min(Student.class, "age", Integer.TYPE);
int realResult = -100;
Cursor cursor = DataSupport.findBySQL("select min(age) from " + studentTable);
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
result = DataSupport.where("age > ?", "10").min(studentTable, "age", Integer.TYPE);
cursor = DataSupport.findBySQL("select min(age) from " + studentTable + " where age > ?", "10");
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
}
示例5: testSum
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testSum() {
int result = DataSupport.sum(Student.class, "age", Integer.TYPE);
int realResult = -100;
Cursor cursor = DataSupport.findBySQL("select sum(age) from " + studentTable);
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
result = DataSupport.where("age > ?", "15").sum(studentTable, "age", Integer.TYPE);
cursor = DataSupport.findBySQL("select sum(age) from " + studentTable + " where age > ?", "15");
if (cursor.moveToFirst()) {
realResult = cursor.getInt(0);
}
cursor.close();
assertEquals(realResult, result);
}
示例6: loadKeyboardListFromLocation
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
/**
* 加载本地关键词数据模型集合
*
* @param keyboard 需要搜索的关键词
* @return 关键词模型集合
*/
public List<KeyboardCache> loadKeyboardListFromLocation(String keyboard) {
if (keyboard.length() == 0) {
return new ArrayList<>();
}
List<KeyboardCache> keyboardCacheList = new ArrayList<>();
Cursor cursor = DataSupport.findBySQL("select * from keyboardcache where keyboard like ? or pinyin like ? order by num desc limit 20", "%" + keyboard + "%", "%" + keyboard + "%");
if (cursor.moveToFirst()) {
do {
KeyboardCache keyboardCache = new KeyboardCache();
keyboardCache.setKeyboard(cursor.getString(cursor.getColumnIndex("keyboard")));
keyboardCache.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
keyboardCache.setNum(cursor.getInt(cursor.getColumnIndex("num")));
keyboardCacheList.add(keyboardCache);
} while (cursor.moveToNext());
}
return keyboardCacheList;
}
示例7: ShowProvince
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void ShowProvince() {
Cursor cursor = DataSupport.findBySQL("SELECT id AS _id, province FROM Location GROUP BY province ORDER BY province");
adapter = new SimpleCursorAdapter(this, R.layout.choose_area_item, cursor,
new String[] {"province"}, new int[] {R.id.place}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
listView.setAdapter(adapter);
chooseWhat.setText("选择省份");
}
示例8: testQueryBySQLWithPlaceHolder
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testQueryBySQLWithPlaceHolder() {
Cursor cursor = DataSupport.findBySQL(
"select * from " + bookTable + " where id=? and bookname=? and pages=?",
String.valueOf(book.getId()), "数据库", "300");
assertTrue(cursor.getCount() == 1);
cursor.moveToFirst();
String bookName = cursor.getString(cursor.getColumnIndexOrThrow("bookname"));
int pages = cursor.getInt(cursor.getColumnIndexOrThrow("pages"));
assertEquals(bookName, "数据库");
assertEquals(pages, 300);
cursor.close();
}
示例9: testQueryBySQLWithWrongParams
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testQueryBySQLWithWrongParams() {
try {
DataSupport.findBySQL("select * from " + bookTable + " where id=? and bookname=? and pages=?",
String.valueOf(book.getId()), "数据库");
fail();
} catch (DataSupportException e) {
assertEquals("The parameters in conditions are incorrect.", e.getMessage());
}
Cursor cursor = DataSupport.findBySQL(new String[] {});
assertNull(cursor);
cursor = DataSupport.findBySQL();
assertNull(cursor);
}
示例10: testDeleteWithGenericData
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testDeleteWithGenericData() {
Classroom classroom = new Classroom();
classroom.setName("classroom1");
classroom.getNews().add("news1");
classroom.getNews().add("news2");
classroom.getNews().add("news3");
classroom.save();
int id = classroom.get_id();
String tableName = DBUtility.getGenericTableName(Classroom.class.getName(), "news");
String column = DBUtility.getGenericValueIdColumnName(Classroom.class.getName());
Cursor c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(id));
assertEquals(3, c.getCount());
c.close();
classroom.delete();
c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(id));
assertEquals(0, c.getCount());
c.close();
assertFalse(classroom.isSaved());
classroom.save();
assertTrue(classroom.isSaved());
c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(classroom.get_id()));
assertEquals(3, c.getCount());
c.close();
DataSupport.deleteAll(Classroom.class, "id = ?", String.valueOf(classroom.get_id()));
c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(classroom.get_id()));
assertEquals(0, c.getCount());
c.close();
}
示例11: ShowCities
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void ShowCities(String province) {
Cursor cursor = DataSupport.findBySQL("SELECT id AS _id, city from Location WHERE province = '"+province+"' GROUP BY city");
adapter.changeCursorAndColumns(cursor, new String[] {"city"}, new int[] {R.id.place});
listView.setSelectionAfterHeaderView();
chooseWhat.setText("选择区域");
}
示例12: ShowPlaces
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void ShowPlaces(String city) {
Cursor cursor = DataSupport.findBySQL("SELECT id AS _id, chname from Location WHERE city = '" + city+"'");
adapter.changeCursorAndColumns(cursor, new String[] {"chname"}, new int[] {R.id.place});
chooseWhat.setText("选择市县");
Map<String, String> mp = new HashMap<>();
}
示例13: testQueryBySQL
import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testQueryBySQL() {
Cursor cursor = DataSupport.findBySQL("select * from " + bookTable);
assertTrue(cursor.getCount() > 0);
cursor.close();
}