public ArrayList<SmallCard> getCardsFromPlayerID(long id) { ArrayList<SmallCard> ds = new ArrayList<SmallCard>(); String retval = ""; Statement stmt; try { stmt = connection.createStatement(); String sql = "SELECT rowid,* FROM cards Where owner= " + id + ";"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { SmallCard d = new SmallCard(); // ( typeId int, owner int, tradeable int, level int) d.cardid = rs.getLong(1); d.typeid = rs.getInt(2); d.owner = rs.getLong(3); d.tradeable = rs.getInt(4); d.level = rs.getInt(5); ds.add(d); } stmt.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ds; }
public ArrayList<Minion> getDeckFromPlayer(String deckname, long playerid, boolean iswhite) { ArrayList<Minion> deck = new ArrayList<Minion>(); Statement stmt; ArrayList<SmallCard> cards = new ArrayList<SmallCard>(); try { stmt = connection.createStatement(); String sql = "SELECT * FROM decks Where owner= " + playerid + " AND name = '" + deckname + "';"; ResultSet rs = stmt.executeQuery(sql); String cs = ""; if (rs.next()) { cs = rs.getString(6); } String inlist = "("; boolean added = false; for (String c : cs.split(",")) { if (added) inlist += ","; inlist += c; added = true; } inlist += ")"; sql = "SELECT rowid,* FROM cards Where owner= " + playerid + " AND rowid IN " + inlist + ";"; rs = stmt.executeQuery(sql); while (rs.next()) { SmallCard d = new SmallCard(); // ( typeId int, owner int, tradeable int, level int) d.cardid = rs.getLong(1); d.typeid = rs.getInt(2); d.owner = rs.getLong(3); d.tradeable = rs.getInt(4); d.level = rs.getInt(5); cards.add(d); } stmt.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } CardDB cdb = CardDB.getInstance(); UColor colw = UColor.black; if (iswhite) colw = UColor.white; for (SmallCard sc : cards) { Minion m = new Minion(cdb.cardId2Card.get(sc.typeid), sc.cardid, colw); m.lvl = sc.level; deck.add(m); } return deck; }