StoreEntity entity = storeList.get(i);
db.execSQL(
"insert into wd_store(" + storeColumns + ") values(?,?,?,?,?,?)",
new Object[]{entity.getStoreId(), entity.getStoreName(), entity.getAreaId(), entity.getAreaName(),
UserManager.getUser().getUserId(),
UserManager.getUser().getUserName()});
}
db.setTransactionSuccessful();
Log.i(TAG, "BasicDataManager---insertStore成功!");
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "BasicDataManager---insertStore错误:" + e.getMessage());
} finally {
db.endTransaction();
}
}
查询并
/**
* @return
*/
public List getArea() {
Cursor cursor = null;
List list = new ArrayList();
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
try {
cursor = db.rawQuery(
"select store_area_id,store_area_name from wd_store where user_id = ? group by store_area_name",
new String[]{UserManager.getUser().getUserId()});
while (cursor.moveToNext()) {
String areaId = cursor.getString(cursor
.getColumnIndex("store_area_id"));
String areaName = cursor.getString(cursor
.getColumnIndex("store_area_name"));
StoreEntity entity = new StoreEntity();
entity.setAreaId(areaId);
entity.setAreaName(areaName);
list.add(entity);
}
Log.i(TAG, "BasicDataManager---getArea成功!");
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "BasicDataManager---getArea错误:" + e.getMessage());
} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
return list;
}
/**
* 查询该用户的所有区域
*
* @return
*/
public List getSXTTArea() {
Cursor cursor = null;
List list = new ArrayList();
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
try {
// cursor = db.rawQuery(
// "select distinct store_id,store_name from sxtt_store where user_id = ? and store_flag =?",
// new String[]{UserManager.getUser().getUserId(),"市"});
// cursor = db.rawQuery(
// "select store_id,store_name from sxtt_store where user_id = ? and store_flag ='省' or store_flag = '市' order by store_name",
// new String[]{UserManager.getUser().getUserId()});
cursor = db.rawQuery("select distinct store_id,store_name from sxtt_store where user_id = ? and store_flag in('省','市') ", new String[]{UserManager.getUser().getUserId()}
);
while (cursor.moveToNext()) {
String areaId = cursor.getString(cursor
.getColumnIndex("store_id"));
String areaName = cursor.getString(cursor
.getColumnIndex("store_name"));
StoreEntity entity = new StoreEntity();
entity.setAreaId(areaId);
entity.setAreaName(areaName);
list.add(entity);
}
Log.i(TAG, "BasicDataManager---getArea成功!");
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "BasicDataManager---getArea错误:" + e.getMessage());
} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
return list;
}
多个条件查询,采用and并使用distinct去重
/**
* @return
*/
public List getSXTTStore(String storeId,String storeFlag) {
Cursor cursor = null;
List list = new ArrayList();
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
try {
cursor = db.rawQuery("select distinct store_id,store_name from sxtt_store where user_id = ? and store_area_id=? and store_flag=?", new String[]{UserManager.getUser().getUserId(), storeId,storeFlag});
while (cursor.moveToNext()) {
String areaId = cursor.getString(cursor
.getColumnIndex("store_id"));
String areaName = cursor.getString(cursor
.getColumnIndex("store_name"));
StoreEntity entity = new StoreEntity();
entity.setAreaId(areaId);
entity.setAreaName(areaName);
list.add(entity);
}
Log.i(TAG, "BasicDataManager---getArea成功!");
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "BasicDataManager---getArea错误:" + e.getMessage());
} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
return list;
}