Guest User

Untitled

a guest
Jul 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public List<Game> getAllGames(String leagueId, String bowlerId, String seriesId) {
  2. List<Game> games = new ArrayList<>();
  3.  
  4. //Select All Query
  5. String selectQuery = "SELECT * FROM " + Game.TABLE_NAME + " WHERE " + Game.COLUMN_LEAGUE_ID + " = '" + leagueId + "'" + " AND " + Game.COLUMN_BOWLER_ID + " = '" + bowlerId + "'" + " AND " + Game.COLUMN_SERIES_ID + " = '" + seriesId + "'" + " ORDER BY " +
  6. Game.COLUMN_TIMESTAMP + " DESC";
  7.  
  8. try (SQLiteDatabase db = this.getWritableDatabase()) {
  9. @SuppressLint("Recycle") Cursor cursor = db.rawQuery( selectQuery, null );
  10.  
  11. //Looping Through All Rows And Adding To The List
  12. if (cursor.moveToFirst()) {
  13. do {
  14. Game game1 = new Game();
  15. game1.setId(cursor.getInt(cursor.getColumnIndex(Game.COLUMN_ID ) ) );
  16. game1.setLeagueId(cursor.getString(cursor.getColumnIndex(Game.COLUMN_LEAGUE_ID)));
  17. game1.setBowlerId(cursor.getString(cursor.getColumnIndex(Game.COLUMN_BOWLER_ID)));
  18. game1.setSeriesId(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SERIES_ID)));
  19. game1.setScore(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SCORE)));
  20. game1.setStrikes(cursor.getString(cursor.getColumnIndex(Game.COLUMN_STRIKES)));
  21. game1.setSpares(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SPARES)));
  22. game1.setSplits(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SPLITS)));
  23. game1.setSplitConversions(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SPLIT_CONVERSIONS)));
  24. game1.setOpenFrames(cursor.getString(cursor.getColumnIndex(Game.COLUMN_OPEN_FRAMES)));
  25. game1.setTimestamp(cursor.getString(cursor.getColumnIndex(Game.COLUMN_TIMESTAMP)));
  26. games.add( game1 );
  27. } while (cursor.moveToNext());
  28. }
  29.  
  30. //Close Database Connection
  31. db.close();
  32. }
  33.  
  34. //Return Game List
  35. return games;
  36. }
  37.  
  38. sqlite> create table test (a int);
  39. sqlite> insert into test values (1);
  40. sqlite> insert into test values (2);
  41. sqlite> insert into test values (3);
  42. sqlite> select avg(a) as average from test;
  43. average
  44. ----------
  45. 2.0
Add Comment
Please, Sign In to add comment