Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addPersonToGroup(String email, String nameGroup) {
- int idGroup = 0;
- int idPerson = 0;
- SQLiteDatabase db1 = this.getReadableDatabase();
- Cursor cursor = db1.query(
- TABLE_PERSON, // The table to query
- new String[]{KEY_PERSON_ID}, // The columns to return
- "email = " + email, // The columns for the WHERE clause
- null, // The values for the WHERE clause
- null, // don't group the rows
- null, // don't filter by row groups
- null // The sort order
- ); // http://stackoverflow.com/questions/1243199/how-to-perform-an-sqlite-query-within-an-android-application
- // http://developer.android.com/training/basics/data-storage/databases.html#ReadDbRow
- if (cursor != null && cursor.moveToFirst()) { // http://www.android4devs.pl/2011/07/sqlite-androidzie-kompletny-poradnik-dla-poczatkujacych/
- idPerson = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_PERSON_ID)));
- }
- Cursor cursor2 = db1.query(
- TABLE_GROUP, // The table to query
- new String[]{KEY_GROUP_ID}, // The columns to return
- "name = " + nameGroup, // The columns for the WHERE clause
- null, // The values for the WHERE clause
- null, // don't group the rows
- null, // don't filter by row groups
- null // The sort order
- ); // http://stackoverflow.com/questions/1243199/how-to-perform-an-sqlite-query-within-an-android-application
- // http://developer.android.com/training/basics/data-storage/databases.html#ReadDbRow
- if (cursor != null && cursor.moveToFirst()) { // http://www.android4devs.pl/2011/07/sqlite-androidzie-kompletny-poradnik-dla-poczatkujacych/
- idGroup = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_GROUP_ID)));
- }
- if (idPerson == 0 || idGroup == 0) {
- Log.e(TAG, "addPersonToGroup idPerson, idGroup " + idPerson + " " + idGroup );
- return;
- }
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put(KEY_PERSONGROUP_IDGROUP, idGroup);
- values.put(KEY_PERSONGROUP_IDPERSON, idPerson);
- long id = db.insert(TABLE_PERSONGROUP, null, values);
- db.close();
- Log.d(TAG, "New PERSONGROUP inserted into sqlite: " + id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement