Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addCode(Code code){
- Log.d("addCode", code.toString());
- // 1. get reference to writable DB
- SQLiteDatabase db = this.getWritableDatabase();
- // 2. create ContentValues to add key "column"/value
- ContentValues values = new ContentValues();
- values.put(KEY_CODE, code.getCode()); // get title
- values.put(KEY_LAT, code.getLat());
- values.put(KEY_LONG, code.getLon());
- //values.put(KEY_locale, code.getAuthor()); // get author
- // 3. insert
- db.insert(TABLE_CODES, // table
- null, //nullColumnHack
- values); // key/value -> keys = column names/ values = column values
- // contId++;
- // 4. close
- db.close();
- }
- public Code getCode(int id){
- // 1. get reference to readable DB
- SQLiteDatabase db = this.getReadableDatabase();
- // 2. build query
- Cursor cursor = db.query(TABLE_CODES, COLUMNS, " id = ?", new String[] { String.valueOf(id) }, null, null, null, null);
- // 3. if we got results get the first one
- if (cursor != null)
- cursor.moveToFirst();
- // 4. build code object
- Code code = new Code();
- code.setId(Integer.parseInt(cursor.getString(0)));
- code.setCode(cursor.getString(1));
- code.setLat(cursor.getString(2));
- code.setLon(cursor.getString(3));
- //code.setAuthor(cursor.getString(2));
- Log.d("getCode("+id+")", code.toString());
- // 5. return book
- return code;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement