/** * query all persons, return list * * @return List<Person> */ public BubblePlayer query(Integer id) { Cursor c = db.rawQuery( "SELECT * FROM starchat_bubbleplayer where id=?", new String[] { Integer.toString(id) }); // db.query("starchat_bubbleplayer",null,null,null,null,null,null); BubblePlayer person = new BubblePlayer(); if (c.getCount() == 1) { c.moveToNext(); person.setId(c.getInt(c.getColumnIndex("id"))); person.setName(c.getString(c.getColumnIndex("name"))); person.setLatitude(c.getDouble(c.getColumnIndex("latitude"))); person.setLontitude(c.getDouble(c.getColumnIndex("lontitude"))); person.setHeadImg(c.getString(c.getColumnIndex("headImg"))); person.setSex(c.getString(c.getColumnIndex("sex"))); c.close(); return person; } else if (c.getCount() > 1) { System.out.print("DBManager: find the ID has more than one BubblePlayer!"); c.close(); return null; } else { c.close(); return null; } }
/** * query all persons, return list * * @return List<Person> */ public ArrayList<BubblePlayer> queryRectBubbles( double LeftUpLat, double LeftUpLon, double RightDownLat, double RightDownLon) { ArrayList<BubblePlayer> persons = new ArrayList<BubblePlayer>(); // db.execSQL("INSERT INTO starchat_bubbleplayer(id, name, latitude, lontitude) VALUES(8, // 'name8', 38, 138)"); Cursor c = db.rawQuery( "SELECT * FROM starchat_bubbleplayer where latitude>? and latitude<? and lontitude>? and lontitude<?", new String[] { String.valueOf(RightDownLat), String.valueOf(LeftUpLat), String.valueOf(LeftUpLon), String.valueOf(RightDownLon) }); while (c.moveToNext()) { BubblePlayer person = new BubblePlayer(); person.setId(c.getInt(c.getColumnIndex("id"))); person.setName(c.getString(c.getColumnIndex("name"))); person.setLatitude(c.getDouble(c.getColumnIndex("latitude"))); person.setLontitude(c.getDouble(c.getColumnIndex("lontitude"))); person.setHeadImg(c.getString(c.getColumnIndex("headImg"))); person.setSex(c.getString(c.getColumnIndex("sex"))); persons.add(person); } c.close(); return persons; }
/** * query all persons, return list * * @return List<Person> */ public ArrayList<BubblePlayer> query() { ArrayList<BubblePlayer> persons = new ArrayList<BubblePlayer>(); // db.execSQL("INSERT INTO starchat_bubbleplayer(id, name, latitude, lontitude) VALUES(8, // 'name8', 38, 138)"); Cursor c = db.rawQuery( "SELECT * FROM starchat_bubbleplayer", null); // db.query("starchat_bubbleplayer",null,null,null,null,null,null); BubblePlayer person = new BubblePlayer(); while (c.moveToNext()) { person.setId(c.getInt(c.getColumnIndex("id"))); person.setName(c.getString(c.getColumnIndex("name"))); person.setLatitude(c.getDouble(c.getColumnIndex("latitude"))); person.setLontitude(c.getDouble(c.getColumnIndex("lontitude"))); person.setHeadImg(c.getString(c.getColumnIndex("headImg"))); person.setSex(c.getString(c.getColumnIndex("sex"))); persons.add(person); } c.close(); return persons; }