コード例 #1
0
  /** Delete a specific host by its <code>_id</code> value. */
  public void deletePubkey(PubkeyBean pubkey) {
    HostDatabase hostdb = new HostDatabase(context);
    hostdb.stopUsingPubkey(pubkey.getId());
    hostdb.close();

    SQLiteDatabase db = getWritableDatabase();
    db.delete(TABLE_PUBKEYS, "_id = ?", new String[] {Long.toString(pubkey.getId())});
    db.close();
  }
コード例 #2
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;
  }
コード例 #3
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;
  }
コード例 #4
0
  /** @param pubkey */
  public PubkeyBean savePubkey(PubkeyBean pubkey) {
    SQLiteDatabase db = this.getWritableDatabase();
    boolean success = false;

    ContentValues values = pubkey.getValues();

    if (pubkey.getId() > 0) {
      values.remove("_id");
      if (db.update(TABLE_PUBKEYS, values, "_id = ?", new String[] {String.valueOf(pubkey.getId())})
          > 0) success = true;
    }

    if (!success) {
      long id = db.insert(TABLE_PUBKEYS, null, pubkey.getValues());
      pubkey.setId(id);
    }

    db.close();

    return pubkey;
  }