******************分页查询***************************
这里使用了query函数进行限制每页查询出来的数量
函数定义如下:
public Cursor query(String table, String[] columns, String selection,
String[] selectionArgs, String groupBy, String having,
String orderBy, String limit) {
return query(false, table, columns, selection, selectionArgs, groupBy,
having, orderBy, limit);
}
?使用方法如下:
List<PassergerInfo> passengerList = new ArrayList<>();
SQLiteDatabase db = mDbHelper.getReadableDatabase();
Cursor cursor = db.query(Table_boardingpassengers,null,null,null,null,null,
null,(currentPage-1)*pageSize+","+currentPage*pageSize);
if(null == cursor || 0 == cursor.getCount()){
Tool_Log.e("SelectBoardingPassenger_Api no data");
return passengerList;
}
while (cursor.moveToNext()){
int id = cursor.getInt(cursor.getColumnIndex("id"));
String flightNum = cursor.getString(cursor.getColumnIndex("flightNum"));
}
******************插入数据***************************
不需要写sql语句,直接用一个容器放置数据
SQLiteDatabase db = mDbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("id",pInfo.id);
values.put("flightNum",pInfo.flightNum);
db.insert(Table_boardingpassengers,null,values);
?
******************删除数据***************************
清空全部数据:
SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.delete(Table_boardingpassengers,null,null);
?
******************更新数据***************************
根据条件更新数据库
?
SQLiteDatabase db = mDbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("isImportant",isImportant);
String[] args = {isImportant+""};
db.update(Table_boardingpassengers,values,"id=?",args);
?
?
?
?
?
?