List of usage examples for android.database.sqlite SQLiteCursor getCount
@Override public int getCount()
From source file:com.chess.genesis.data.GameDataDB.java
public long getNewestOnlineTime() { final String username = getUsername(); final String[] data = { username, username }; final String query = "SELECT stime FROM onlinegames WHERE white=? OR black=? ORDER BY stime DESC LIMIT 1"; final SQLiteCursor cursor = (SQLiteCursor) db.rawQuery(query, data); try {/*from ww w . ja v a2s. co m*/ if (cursor.getCount() == 0) return 0; cursor.moveToFirst(); return cursor.getLong(0); } finally { cursor.close(); } }
From source file:com.chess.genesis.data.GameDataDB.java
public void recalcYourTurn() { final String username = getUsername(); final String[] data = { username, username }; final String query = "SELECT gameid, status, history, white, drawoffer FROM onlinegames WHERE white=? or black=?;"; final SQLiteCursor cursor = (SQLiteCursor) db.rawQuery(query, data); cursor.moveToFirst();/*from w w w .j a va2 s . c o m*/ for (int i = 0, len = cursor.getCount(); i < len; i++) { final String gameid = cursor.getString(0); final int status = cursor.getInt(1); final String history = cursor.getString(2); final String white = cursor.getString(3); final int drawoffer = cursor.getInt(4); final GameInfo info = new GameInfo(context, status, history, white, drawoffer); final Object[] data2 = { info.getYourTurn(), gameid }; db.execSQL("UPDATE onlinegames SET yourturn=? WHERE gameid=?;", data2); cursor.moveToNext(); } cursor.close(); }
From source file:com.chess.genesis.data.GameDataDB.java
public void updateOnlineGame(final JSONObject json) { try {//w w w .j a va 2s . co m final String gameid = json.getString("gameid"); if (json.optBoolean("delete", false)) { deleteOnlineGame(gameid); return; } final String[] data1 = { gameid }; final SQLiteCursor cursor = (SQLiteCursor) db.rawQuery("SELECT * FROM onlinegames WHERE gameid=?", data1); if (cursor.getCount() < 1) { if (!checkArchiveGame(gameid)) insertOnlineGame(json); cursor.close(); return; } final String zfen = json.getString("zfen"); final String history = json.getString("history"); final long stime = json.getLong("stime"); final int status = Enums.GameStatus(json.getString("status")); final int idle = (json.has("idle") ? 1 : 0) + (json.has("nudge") ? 1 : 0) + (json.has("close") ? 1 : 0); final int drawoffer = json.has("drawoffer") ? (json.getString("drawoffer").equals("white") ? Piece.WHITE : Piece.BLACK) : 0; final Bundle row = rowToBundle(cursor, 0, true); final GameInfo info = new GameInfo(context, status, history, row.getString("white"), drawoffer); final int ply = info.getPly(), yourturn = info.getYourTurn(); final Object[] data2 = { stime, status, ply, yourturn, zfen, history, idle, drawoffer, gameid }; db.execSQL( "UPDATE onlinegames SET stime=?, status=?, ply=?, yourturn=?, zfen=?, history=?, idle=?, drawoffer=? WHERE gameid=?;", data2); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.data.GameDataDB.java
public List<String> getOnlineGameIds() { final String username = getUsername(); final String[] data = { username, username }; final SQLiteCursor cursor = (SQLiteCursor) db .rawQuery("SELECT gameid FROM onlinegames WHERE white=? OR black=?", data); final List<String> list = new ArrayList<String>(cursor.getCount()); cursor.moveToFirst();//from w w w .j av a 2s . com for (int i = 0, len = cursor.getCount(); i < len; i++) { list.add(cursor.getString(0)); cursor.moveToNext(); } cursor.close(); return list; }
From source file:com.chess.genesis.data.GameDataDB.java
public List<String> getArchiveGameIds() { final String username = getUsername(); final String[] data = { username, username }; final SQLiteCursor cursor = (SQLiteCursor) db .rawQuery("SELECT gameid FROM archivegames WHERE white=? OR black=?", data); final List<String> list = new ArrayList<String>(cursor.getCount()); cursor.moveToFirst();//from w ww . j a v a 2 s. c o m for (int i = 0, len = cursor.getCount(); i < len; i++) { list.add(cursor.getString(0)); cursor.moveToNext(); } cursor.close(); return list; }
From source file:com.chess.genesis.data.GameDataDB.java
public long getNewestMsg() { final String username = getUsername(); final String[] data = { username, username }; final SQLiteCursor cursor = (SQLiteCursor) db.rawQuery( "SELECT time FROM msgtable WHERE username=? OR opponent=? ORDER BY time DESC LIMIT 1", data); try {/* w w w. j a v a2 s . c o m*/ if (cursor.getCount() == 0) return 0; cursor.moveToFirst(); return cursor.getLong(0); } finally { cursor.close(); } }