本文整理匯總了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();
}