コード例 #1
0
  private PubkeyBean createPubkeyBean(Cursor c) {
    PubkeyBean pubkey = new PubkeyBean();

    pubkey.setId(c.getLong(c.getColumnIndexOrThrow("_id")));
    pubkey.setNickname(c.getString(c.getColumnIndexOrThrow(FIELD_PUBKEY_NICKNAME)));
    pubkey.setType(c.getString(c.getColumnIndexOrThrow(FIELD_PUBKEY_TYPE)));
    pubkey.setPrivateKey(c.getBlob(c.getColumnIndexOrThrow(FIELD_PUBKEY_PRIVATE)));
    pubkey.setPublicKey(c.getBlob(c.getColumnIndexOrThrow(FIELD_PUBKEY_PUBLIC)));
    pubkey.setEncrypted(c.getInt(c.getColumnIndexOrThrow(FIELD_PUBKEY_ENCRYPTED)) > 0);
    pubkey.setStartup(c.getInt(c.getColumnIndexOrThrow(FIELD_PUBKEY_STARTUP)) > 0);
    pubkey.setConfirmUse(c.getInt(c.getColumnIndexOrThrow(FIELD_PUBKEY_CONFIRMUSE)) > 0);
    pubkey.setLifetime(c.getInt(c.getColumnIndexOrThrow(FIELD_PUBKEY_LIFETIME)));

    return pubkey;
  }
コード例 #2
0
  private List<PubkeyBean> getPubkeys(String selection, String[] selectionArgs) {
    SQLiteDatabase db = getReadableDatabase();

    List<PubkeyBean> pubkeys = new LinkedList<PubkeyBean>();

    Cursor c = db.query(TABLE_PUBKEYS, null, selection, selectionArgs, null, null, null);

    if (c != null) {
      final int COL_ID = c.getColumnIndexOrThrow("_id"),
          COL_NICKNAME = c.getColumnIndexOrThrow(FIELD_PUBKEY_NICKNAME),
          COL_TYPE = c.getColumnIndexOrThrow(FIELD_PUBKEY_TYPE),
          COL_PRIVATE = c.getColumnIndexOrThrow(FIELD_PUBKEY_PRIVATE),
          COL_PUBLIC = c.getColumnIndexOrThrow(FIELD_PUBKEY_PUBLIC),
          COL_ENCRYPTED = c.getColumnIndexOrThrow(FIELD_PUBKEY_ENCRYPTED),
          COL_STARTUP = c.getColumnIndexOrThrow(FIELD_PUBKEY_STARTUP),
          COL_CONFIRMUSE = c.getColumnIndexOrThrow(FIELD_PUBKEY_CONFIRMUSE),
          COL_LIFETIME = c.getColumnIndexOrThrow(FIELD_PUBKEY_LIFETIME);

      while (c.moveToNext()) {
        PubkeyBean pubkey = new PubkeyBean();

        pubkey.setId(c.getLong(COL_ID));
        pubkey.setNickname(c.getString(COL_NICKNAME));
        pubkey.setType(c.getString(COL_TYPE));
        pubkey.setPrivateKey(c.getBlob(COL_PRIVATE));
        pubkey.setPublicKey(c.getBlob(COL_PUBLIC));
        pubkey.setEncrypted(c.getInt(COL_ENCRYPTED) > 0);
        pubkey.setStartup(c.getInt(COL_STARTUP) > 0);
        pubkey.setConfirmUse(c.getInt(COL_CONFIRMUSE) > 0);
        pubkey.setLifetime(c.getInt(COL_LIFETIME));

        pubkeys.add(pubkey);
      }

      c.close();
    }

    db.close();

    return pubkeys;
  }