Example usage for android.database.sqlite SQLiteCursor close

List of usage examples for android.database.sqlite SQLiteCursor close

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteCursor close.

Prototype

@Override
    public void close() 

Source Link

Usage

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 ww. ja v a  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 {//w  w w .ja  v  a 2  s . 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 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 {//w w w . j  a  v  a 2s . c  o  m
        cursor.moveToFirst();
        return cursor.getInt(0);
    } finally {
        cursor.close();
    }
}

From source file:com.chess.genesis.data.GameDataDB.java

public void updateOnlineGame(final JSONObject json) {
    try {/*from   w w  w  .  ja v  a 2 s  .  c o  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 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  . j a v  a  2  s. c om
        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 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();//  w w w . j a  v  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();//w  w w  . j a  va2  s  .c om
    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 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();/*  w w  w. jav  a 2s. c om*/
    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();
}