コード例 #1
0
ファイル: Vote.java プロジェクト: jwegan/parseexception
  public boolean setUpvote(int v) {
    StatementHandle hndl;
    String query;

    if (vote == 0) {
      query = "INSERT INTO votes (upvote, uid, sid) VALUES (?, ?, ?)";
      hndl = insert_vote;
    } else {
      query = "UPDATE votes SET upvote = ? WHERE uid = ? AND sid = ?";
      hndl = set_vote;
    }

    ArrayList<Object> args = new ArrayList<Object>();
    args.add(new Integer(v));
    args.add(new Integer(uid));
    args.add(new Integer(sid));

    boolean ret;
    if (vote == 0) ret = DataAccess.createEntry(hndl, query, "id", args) > 0;
    else ret = DataAccess.update(hndl, query, args);
    if (ret) {
      vote = v;
      Solution s = Solution.getSolution(sid);
      s.setScore();
    }

    return ret;
  }