List of usage examples for android.database.sqlite SQLiteCursor moveToFirst
@Override public final boolean moveToFirst()
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(); 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();/*from w w w . j av a 2 s . c om*/ } cursor.close(); }
From source file:com.chess.genesis.data.GameDataDB.java
public int getUnreadMsgCount() { final String username = getUsername(); final String[] data = { username, username }; final String query = "SELECT COUNT(*) FROM msgtable WHERE unread=1 AND (username=? OR opponent=?)"; final SQLiteCursor cursor = (SQLiteCursor) db.rawQuery(query, data); try {/*from w w w . j a va 2 s . co m*/ cursor.moveToFirst(); return cursor.getInt(0); } finally { cursor.close(); } }
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 w ww . j ava 2 s.c o 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 int getUnreadMsgCount(final String gameid) { final String[] data = { gameid }; final SQLiteCursor cursor = (SQLiteCursor) db .rawQuery("SELECT COUNT(unread) FROM msgtable WHERE unread=1 AND gameid=?", data); try {/*from ww w .java 2 s . co m*/ cursor.moveToFirst(); return cursor.getInt(0); } finally { cursor.close(); } }
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(); for (int i = 0, len = cursor.getCount(); i < len; i++) { list.add(cursor.getString(0));/* w ww . j a v a2s . com*/ 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(); for (int i = 0, len = cursor.getCount(); i < len; i++) { list.add(cursor.getString(0));//from ww w .ja v a2 s . c o m 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 {/*from www. java 2 s .c o m*/ if (cursor.getCount() == 0) return 0; cursor.moveToFirst(); return cursor.getLong(0); } finally { cursor.close(); } }