Example #1
0
    public void delete(Host host) {
      if (host.getId() < 0) return;

      SQLiteDatabase db = getWritableDatabase();
      db.delete(TABLE_HOSTS, "_id = ?", new String[] {String.valueOf(host.getId())});
      db.close();
    }
Example #2
0
    public void update(Host host) {
      SQLiteDatabase db = getReadableDatabase();

      ContentValues values = host.getValues();

      db.update(TABLE_HOSTS, values, "_id =?", new String[] {String.valueOf(host.getId())});

      db.close();
    }
Example #3
0
    public Host insert(Host host) {
      SQLiteDatabase db = getWritableDatabase();

      ContentValues values = host.getValues();
      long id = db.insert(TABLE_HOSTS, null, values);
      db.close();

      host.setId(id);
      return host;
    }
Example #4
0
    // ´Ódb  µ½  pref
    public List<Host> get() {
      List<Host> hosts = new LinkedList<Host>();

      SQLiteDatabase db = getReadableDatabase();
      Cursor c = db.query(TABLE_HOSTS, null, null, null, null, null, FIELD_HOSTS_NAME + " ASC");

      while (c.moveToNext()) {
        Host host = new Host();

        host.setId(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_ID)));
        host.setName(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_NAME)));
        host.setProtocal(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_PROTOCAL)));
        host.setEncoding(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_ENCODING)));
        host.setUser(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_USER)));
        host.setPass(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_PASS)));
        host.setHost(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_HOST)));
        host.setPort(c.getInt(c.getColumnIndexOrThrow(FIELD_HOSTS_PORT)));

        host.setRss(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_RSS)));
        host.setAquirespan(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_AQUIRESPAN)));
        host.setAlamspan(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_ALARMSPAN)));
        host.setWorkStartTime(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_STARTTIME)));
        host.setWorkEndTime(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_ENDTIME)));
        host.setAlarmInWorktime(c.getInt(c.getColumnIndexOrThrow(FIELD_HOSTS_ALARMINWORKTIME)));

        hosts.add(host);
      }

      c.close();
      db.close();

      return hosts;
    }
Example #5
0
    public Host getHost(long id) {
      SQLiteDatabase db = getReadableDatabase();
      Cursor c =
          db.query(
              TABLE_HOSTS,
              null,
              "_id=?",
              new String[] {"" + id},
              null,
              null,
              FIELD_HOSTS_NAME + " ASC");

      Host host = null;
      if (c != null && c.moveToFirst()) {
        host = new Host();

        host.setId(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_ID)));
        host.setName(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_NAME)));
        host.setProtocal(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_PROTOCAL)));
        host.setEncoding(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_ENCODING)));
        host.setUser(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_USER)));
        host.setPass(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_PASS)));
        host.setHost(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_HOST)));
        host.setPort(c.getInt(c.getColumnIndexOrThrow(FIELD_HOSTS_PORT)));

        host.setRss(c.getString(c.getColumnIndexOrThrow(FIELD_HOSTS_RSS)));
        host.setAquirespan(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_AQUIRESPAN)));
        host.setAlamspan(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_ALARMSPAN)));
        host.setWorkStartTime(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_STARTTIME)));
        host.setWorkEndTime(c.getLong(c.getColumnIndexOrThrow(FIELD_HOSTS_ENDTIME)));
        host.setAlarmInWorktime(c.getInt(c.getColumnIndexOrThrow(FIELD_HOSTS_ALARMINWORKTIME)));
      }
      c.close();
      db.close();

      return host;
    }