当前位置: 首页>>代码示例>>Java>>正文


Java DataSupport.findBySQL方法代码示例

本文整理汇总了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) {
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:QueryMathTest.java

示例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();
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:QueryMathTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:QueryMathTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:QueryMathTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:QueryMathTest.java

示例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;
}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:24,代码来源:NewsDALManager.java

示例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("选择省份");
}
 
开发者ID:miradilabk,项目名称:UyghurWeather,代码行数:8,代码来源:ChooseAreaActivity.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:QueryBySQLTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:QueryBySQLTest.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:DeleteTest.java

示例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("选择区域");
}
 
开发者ID:miradilabk,项目名称:UyghurWeather,代码行数:7,代码来源:ChooseAreaActivity.java

示例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<>();
}
 
开发者ID:miradilabk,项目名称:UyghurWeather,代码行数:7,代码来源:ChooseAreaActivity.java

示例13: testQueryBySQL

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testQueryBySQL() {
	Cursor cursor = DataSupport.findBySQL("select * from " + bookTable);
	assertTrue(cursor.getCount() > 0);
	cursor.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:QueryBySQLTest.java


注:本文中的org.litepal.crud.DataSupport.findBySQL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。