Advertisement
PomozMi

Untitled

Nov 25th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1.     public void addPersonToGroup(String email, String nameGroup) {
  2.         int idGroup = 0;
  3.         int idPerson = 0;
  4.  
  5.         SQLiteDatabase db1 = this.getReadableDatabase();
  6.  
  7.         Cursor cursor = db1.query(
  8.                 TABLE_PERSON,                            // The table to query
  9.                 new String[]{KEY_PERSON_ID},            // The columns to return
  10.                 "email = " + email,                    // The columns for the WHERE clause
  11.                 null,                                    // The values for the WHERE clause
  12.                 null,                                   // don't group the rows
  13.                 null,                                    // don't filter by row groups
  14.                 null                                    // The sort order
  15.         );  // http://stackoverflow.com/questions/1243199/how-to-perform-an-sqlite-query-within-an-android-application
  16.         // http://developer.android.com/training/basics/data-storage/databases.html#ReadDbRow
  17.  
  18.         if (cursor != null && cursor.moveToFirst()) { // http://www.android4devs.pl/2011/07/sqlite-androidzie-kompletny-poradnik-dla-poczatkujacych/
  19.             idPerson = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_PERSON_ID)));
  20.         }
  21.  
  22.  
  23.         Cursor cursor2 = db1.query(
  24.                 TABLE_GROUP,                            // The table to query
  25.                 new String[]{KEY_GROUP_ID},            // The columns to return
  26.                 "name = " + nameGroup,                    // The columns for the WHERE clause
  27.                 null,                                    // The values for the WHERE clause
  28.                 null,                                   // don't group the rows
  29.                 null,                                    // don't filter by row groups
  30.                 null                                    // The sort order
  31.         );  // http://stackoverflow.com/questions/1243199/how-to-perform-an-sqlite-query-within-an-android-application
  32.         // http://developer.android.com/training/basics/data-storage/databases.html#ReadDbRow
  33.  
  34.         if (cursor != null && cursor.moveToFirst()) { // http://www.android4devs.pl/2011/07/sqlite-androidzie-kompletny-poradnik-dla-poczatkujacych/
  35.             idGroup = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_GROUP_ID)));
  36.         }
  37.  
  38.         if (idPerson == 0 || idGroup == 0) {
  39.             Log.e(TAG, "addPersonToGroup  idPerson, idGroup " + idPerson + " " + idGroup );
  40.             return;
  41.         }
  42.  
  43.         SQLiteDatabase db = this.getWritableDatabase();
  44.  
  45.         ContentValues values = new ContentValues();
  46.         values.put(KEY_PERSONGROUP_IDGROUP, idGroup);
  47.         values.put(KEY_PERSONGROUP_IDPERSON, idPerson);
  48.  
  49.         long id = db.insert(TABLE_PERSONGROUP, null, values);
  50.         db.close();
  51.  
  52.         Log.d(TAG, "New PERSONGROUP inserted into sqlite: " + id);
  53.  
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement