Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. public class LocationsSQLHelper extends SQLiteOpenHelper {
  2.  
  3. private SQLiteDatabase mDB;
  4. public static final String DATABASE_NAME = "MyDBName.db";
  5. private static final String TABLE_NAME="locations";
  6.  
  7. private static final String FIELD_ROW_ID="loc_id";
  8. private static final String FIELD_LAT="loc_lat";
  9. private static final String FIELD_LNG="loc_lng";
  10. private static final String FIELD_ZOOM="loc_pos";
  11.  
  12. private static final int D_VERSION=1;
  13.  
  14. private static final String DB_NAME="markerlocations.db";
  15. private static final String DB_CREATE="create table "+TABLE_NAME+ "("
  16. +FIELD_ROW_ID + "integer primary key autoincrement, "
  17. +FIELD_LAT + "double , "
  18. +FIELD_LNG + "double ,"
  19. +FIELD_ZOOM + "text"
  20. +");"
  21. ;
  22.  
  23.  
  24. public LocationsSQLHelper(Context context) {
  25. super(context, DB_NAME, null, D_VERSION);
  26.  
  27. }
  28.  
  29. @Override
  30. public void onCreate(SQLiteDatabase db) {
  31. db.execSQL(DB_CREATE);
  32. }
  33.  
  34.  
  35. /** Inserts a new location to the table locations */
  36. public boolean insert(Integer id, Double lat, Double lon, String zoom) {
  37. SQLiteDatabase db=this.getWritableDatabase();
  38. ContentValues contentValues=new ContentValues();
  39. contentValues.put("id", id);
  40. contentValues.put("lat", 12.944400 );
  41. contentValues.put("lon", 75.785966);
  42. contentValues.put(zoom,"zoom");
  43. return true;
  44. }
  45.  
  46. /** Deletes all locations from the table */
  47. public long del(Integer id){
  48. SQLiteDatabase db = this.getWritableDatabase();
  49. return db.delete("locations",
  50. "id = ? ",
  51. new String[] { Long.toString(id) });
  52. }
  53.  
  54. public ArrayList<String> getAllLocations(){
  55. ArrayList<String> arrayList=new ArrayList<>();
  56. SQLiteDatabase db=this.getReadableDatabase();
  57. Cursor res=db.rawQuery("select * from locations", null );
  58. res.moveToFirst();
  59. while(res.isAfterLast() == false){
  60. arrayList.add(res.getString(res.getColumnIndex(FIELD_ROW_ID)));
  61. res.moveToNext();
  62. }
  63. return arrayList;
  64. }
  65.  
  66. @Override
  67. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  68. db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
  69. onCreate(db);
  70. }
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement