Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. public static final String READINGS_CREATE = "CREATE TABLE 'readings' ('building_id' TEXT NOT NULL , "
  2. + "'position_id' TEXT NOT NULL , 'x' FLOAT NOT NULL, 'y' FLOAT NOT NULL, "
  3. + " 'ssid' TEXT NOT NULL , 'mac_id' TEXT NOT NULL , 'rssi' INTEGER NOT NULL )";
  4.  
  5. public ArrayList<String> getPositions(String building_id) {
  6. SQLiteDatabase db = getReadableDatabase();
  7. Cursor cursor = db.rawQuery("select distinct position_id from "
  8. + READINGS_TABLE + " where building_id=?",
  9. new String[] { building_id });
  10. ArrayList<String> result = new ArrayList<String>();
  11. cursor.moveToFirst();
  12. while (cursor.isAfterLast() == false) {
  13. result.add(cursor.getString(0));
  14. cursor.moveToNext();
  15. }
  16. return result;
  17. }
  18.  
  19. public boolean addReadings(String building_id, PositionData positionData) {
  20. Log.v("Just Before db : ", positionData.toString());
  21. deleteReading(building_id, positionData.getName());
  22.  
  23. SQLiteDatabase db = getWritableDatabase();
  24. for (Map.Entry<String, Integer> e : positionData.getValues().entrySet()) {
  25. ContentValues cv = new ContentValues();
  26. cv.put("building_id", building_id);
  27. cv.put("position_id", positionData.getName());
  28. cv.put("ssid",positionData.routers.get(e.getKey()));
  29. cv.put("mac_id",e.getKey());
  30. cv.put("rssi", e.getValue());
  31. cv.put("x", positionData.getX());
  32. cv.put("y", positionData.getY());
  33. Log.v(e.getKey(), e.getValue().toString());
  34. db.insert(READINGS_TABLE, null, cv);
  35.  
  36. }
  37. System.out.println("Adding done");
  38. return true;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement