Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Game> getAllGames(String leagueId, String bowlerId, String seriesId) {
- List<Game> games = new ArrayList<>();
- //Select All Query
- 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 " +
- Game.COLUMN_TIMESTAMP + " DESC";
- try (SQLiteDatabase db = this.getWritableDatabase()) {
- @SuppressLint("Recycle") Cursor cursor = db.rawQuery( selectQuery, null );
- //Looping Through All Rows And Adding To The List
- if (cursor.moveToFirst()) {
- do {
- Game game1 = new Game();
- game1.setId(cursor.getInt(cursor.getColumnIndex(Game.COLUMN_ID ) ) );
- game1.setLeagueId(cursor.getString(cursor.getColumnIndex(Game.COLUMN_LEAGUE_ID)));
- game1.setBowlerId(cursor.getString(cursor.getColumnIndex(Game.COLUMN_BOWLER_ID)));
- game1.setSeriesId(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SERIES_ID)));
- game1.setScore(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SCORE)));
- game1.setStrikes(cursor.getString(cursor.getColumnIndex(Game.COLUMN_STRIKES)));
- game1.setSpares(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SPARES)));
- game1.setSplits(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SPLITS)));
- game1.setSplitConversions(cursor.getString(cursor.getColumnIndex(Game.COLUMN_SPLIT_CONVERSIONS)));
- game1.setOpenFrames(cursor.getString(cursor.getColumnIndex(Game.COLUMN_OPEN_FRAMES)));
- game1.setTimestamp(cursor.getString(cursor.getColumnIndex(Game.COLUMN_TIMESTAMP)));
- games.add( game1 );
- } while (cursor.moveToNext());
- }
- //Close Database Connection
- db.close();
- }
- //Return Game List
- return games;
- }
- sqlite> create table test (a int);
- sqlite> insert into test values (1);
- sqlite> insert into test values (2);
- sqlite> insert into test values (3);
- sqlite> select avg(a) as average from test;
- average
- ----------
- 2.0
Add Comment
Please, Sign In to add comment