// get single team with name public Teams getTeam(String t_name) { if (_local) { SQLiteDatabase db = this.getReadableDatabase(); // create query to select game String selectQuery = "SELECT * FROM " + TABLE_TEAMS + " WHERE " + KEY_T_NAME + " = " + t_name; // Log the query Log.i(LOG, selectQuery); // perform the query and store data in cursor Cursor c = db.rawQuery(selectQuery, null); // set cursor to beginning if (c != null) c.moveToFirst(); // create the instance of Teams using cursor information Teams team = new Teams(); team.settid(c.getLong(c.getColumnIndex(KEY_T_ID))); team.settname((c.getString(c.getColumnIndex(KEY_T_NAME)))); team.setabbv((c.getString(c.getColumnIndex(KEY_ABBV)))); team.setcname((c.getString(c.getColumnIndex(KEY_C_NAME)))); team.setsport((c.getString(c.getColumnIndex(KEY_SPORT)))); return team; } else { return _net.getTeam(t_name); } }
public List<Teams> getAllTeams() { if (_local) { SQLiteDatabase db = this.getReadableDatabase(); List<Teams> teams = new ArrayList<Teams>(); String selectQuery = "SELECT * FROM " + TABLE_TEAMS; Log.i(LOG, selectQuery); Cursor c = db.rawQuery(selectQuery, null); if (c != null && c.moveToFirst()) { do { // create the instance of Players using cursor information Teams team = new Teams(); team.settid(c.getLong(c.getColumnIndex(KEY_T_ID))); team.settname((c.getString(c.getColumnIndex(KEY_T_NAME)))); team.setabbv((c.getString(c.getColumnIndex(KEY_ABBV)))); team.setcname((c.getString(c.getColumnIndex(KEY_C_NAME)))); team.setsport((c.getString(c.getColumnIndex(KEY_SPORT)))); // adding to players list teams.add(team); } while (c.moveToNext()); } return teams; } else { return _net.getAllTeams(); } }
// Delete a Shot public void deleteShot(long shot_id) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_SHOT_CHART_COORDS, KEY_SHOT_ID + " = " + shot_id, null); if (!_local) { _net.deleteShot(shot_id); } }
// Delete a Player public void deletePlayer(long p_id) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_PLAYERS, KEY_P_ID + " = " + p_id, null); if (!_local) { _net.deletePlayer(p_id); } }
public List<ShotChartCoords> getAllPlayerShots(long p_id) { if (_local) { SQLiteDatabase db = this.getReadableDatabase(); List<ShotChartCoords> shots = new ArrayList<ShotChartCoords>(); String selectQuery = "SELECT * FROM " + TABLE_SHOT_CHART_COORDS + "WHERE " + KEY_P_ID + " = " + p_id; Log.i(LOG, selectQuery); Cursor c = db.rawQuery(selectQuery, null); if (c != null && c.moveToFirst()) { do { // create the instance of Players using cursor information ShotChartCoords shot = new ShotChartCoords(); shot.setshotid(c.getLong(c.getColumnIndex(KEY_SHOT_ID))); shot.setgid((c.getLong(c.getColumnIndex(KEY_G_ID)))); shot.setpid((c.getLong(c.getColumnIndex(KEY_P_ID)))); shot.settid((c.getLong(c.getColumnIndex(KEY_T_ID)))); shot.setx((c.getInt(c.getColumnIndex(KEY_X)))); shot.sety((c.getInt(c.getColumnIndex(KEY_Y)))); shot.setmade((c.getString(c.getColumnIndex(KEY_MADE)))); // adding to players list shots.add(shot); } while (c.moveToNext()); } return shots; } else { return _net.getAllPlayerShots(p_id); } }
// Delete Players on a team public void deletePlayers(long t_id) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_PLAYERS, KEY_T_ID + " = ?", new String[] {String.valueOf(t_id)}); if (!_local) { _net.deletePlayer(t_id); } }
public List<Players> getAllPlayers() { if (_local) { SQLiteDatabase db = this.getReadableDatabase(); List<Players> players = new ArrayList<Players>(); String selectPlayerQuery = "SELECT * FROM " + TABLE_PLAYERS; Log.i(LOG, selectPlayerQuery); Cursor c = db.rawQuery(selectPlayerQuery, null); if (c != null && c.moveToFirst()) { do { // create the instance of Players using cursor information Players player = new Players(); player.setpid(c.getLong(c.getColumnIndex(KEY_P_ID))); player.settid(c.getLong(c.getColumnIndex(KEY_T_ID))); player.setpname((c.getString(c.getColumnIndex(KEY_P_NAME)))); player.setpnum((c.getInt(c.getColumnIndex(KEY_P_NUM)))); // adding to players list players.add(player); } while (c.moveToNext()); } return players; } else { return _net.getAllPlayers(); } }
public List<PlayByPlay> getPlayByPlayGame(long g_id) { if (_local) { SQLiteDatabase db = this.getReadableDatabase(); List<PlayByPlay> pbps = new ArrayList<PlayByPlay>(); String selectPlayByPlayQuery = "SELECT * FROM " + TABLE_PLAY_BY_PLAY + " WHERE " + KEY_G_ID + " = " + g_id; Log.i(LOG, selectPlayByPlayQuery); Cursor c = db.rawQuery(selectPlayByPlayQuery, null); if (c != null && c.moveToFirst()) { do { // create the instance of Players using cursor information PlayByPlay pbp = new PlayByPlay(); pbp.setaid(c.getLong(c.getColumnIndex(KEY_A_ID))); pbp.setgid(c.getLong(c.getColumnIndex(KEY_G_ID))); pbp.setaction(c.getString(c.getColumnIndex(KEY_ACTION))); pbp.settime(c.getString(c.getColumnIndex(KEY_TIME))); pbp.setperiod(c.getString(c.getColumnIndex(KEY_PERIOD))); pbp.sethomescore(c.getInt(c.getColumnIndex(KEY_HOME_SCORE))); pbp.setawayscore(c.getInt(c.getColumnIndex(KEY_AWAY_SCORE))); // adding to playbyplay list pbps.add(pbp); } while (c.moveToNext()); } return pbps; } else { return _net.getPlayByPlayGame(g_id); } }
// Delete PlayByPlay of a game public void deletePlayByPlayGame(long g_id) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_PLAY_BY_PLAY, KEY_G_ID + " = ?", new String[] {String.valueOf(g_id)}); if (!_local) { _net.deletePlayByPlayGame(g_id); } }
public int updatePlayer(Players player) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_T_ID, player.gettid()); values.put(KEY_P_NAME, player.getpname()); values.put(KEY_P_NUM, player.getpnum()); if (!_local) { _net.updatePlayer(player); } return db.update( TABLE_PLAYERS, values, KEY_P_ID + " = ?", new String[] {String.valueOf(player.getpid())}); }
public int updateTeam(Teams team) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_T_NAME, team.gettname()); values.put(KEY_ABBV, team.getabbv()); values.put(KEY_C_NAME, team.getcname()); values.put(KEY_SPORT, team.getSport()); if (!_local) { _net.updateTeam(team); } return db.update( TABLE_TEAMS, values, KEY_T_ID + " = ?", new String[] {String.valueOf(team.gettid())}); }
public long createTeams(Teams team) { SQLiteDatabase db = this.getWritableDatabase(); Log.i("INTEG-EX", "starting create teams"); ContentValues values = new ContentValues(); // values.put(KEY_T_ID, team.gettid()); values.put(KEY_T_NAME, team.gettname()); values.put(KEY_ABBV, team.getabbv()); values.put(KEY_C_NAME, team.getcname()); values.put(KEY_SPORT, team.getSport()); // insert row long p_id = db.insert(TABLE_TEAMS, null, values); if (!_local) { _net.createTeams(team, p_id); } return p_id; }
public long createPlayByPlay(PlayByPlay pbp) { SQLiteDatabase db = this.getWritableDatabase(); Log.i("INTEG", "starting play by play creation"); ContentValues values = new ContentValues(); values.put(KEY_G_ID, pbp.getgid()); values.put(KEY_ACTION, pbp.getaction()); values.put(KEY_TIME, pbp.gettime()); values.put(KEY_PERIOD, pbp.getperiod()); values.put(KEY_HOME_SCORE, pbp.gethomescore()); values.put(KEY_AWAY_SCORE, pbp.getawayscore()); // insert row long a_id = db.insert(TABLE_PLAY_BY_PLAY, null, values); pbp.setaid(a_id); if (!_local) { Log.i("INTEG", "entering network pbp creation"); _net.createPlayByPlay(pbp, a_id); } return a_id; }
// create a row of shot chart coordinates public long createShot(ShotChartCoords shot) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_G_ID, shot.getgid()); values.put(KEY_P_ID, shot.getpid()); values.put(KEY_T_ID, shot.gettid()); values.put(KEY_X, shot.getx()); values.put(KEY_Y, shot.gety()); values.put(KEY_MADE, shot.getmade()); // insert row long shot_id = db.insert(TABLE_SHOT_CHART_COORDS, null, values); shot.setshotid(shot_id); _undoInstance.setshot(shot); if (!_local) { _net.createShot(shot, shot_id); } return shot_id; }