Ejemplo n.º 1
0
 /** 添加邮箱账号 */
 public MailAccount getMailAccountByAddress(MailAccount account) {
   String sql =
       "select username, password, mailType, resId, unReadCount from t_mail_account where emailAddress = ?";
   SQLiteDatabase db = dbHelper.getReadableDatabase();
   Cursor cursor = null;
   try {
     String[] args = {account.getEmailAddress()};
     cursor = db.rawQuery(sql, args);
     if (cursor.moveToFirst()) {
       MailAccount ma = new MailAccount();
       ma.setUsername(cursor.getString(cursor.getColumnIndex("username")));
       ma.setPassword(cursor.getString(cursor.getColumnIndex("password")));
       ma.setMailType(cursor.getString(cursor.getColumnIndex("mailType")));
       ma.setResId(cursor.getInt(cursor.getColumnIndex("resId")));
       ma.setUnReadCount(cursor.getInt(cursor.getColumnIndex("unReadCount")));
       ma.setEmailAddress(account.getEmailAddress());
       return ma;
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
     db.close();
   }
   return null;
 }
Ejemplo n.º 2
0
 public List<MailAccount> listAccount() {
   String sql =
       "select username, password, emailAddress, mailType, resId, unReadCount from t_mail_account";
   SQLiteDatabase db = dbHelper.getReadableDatabase();
   List<MailAccount> accounts = null;
   Cursor cursor = null;
   try {
     cursor = db.rawQuery(sql, null);
     accounts = new ArrayList<MailAccount>();
     while (cursor.moveToNext()) {
       MailAccount account = new MailAccount();
       account.setUsername(cursor.getString(cursor.getColumnIndex("username")));
       account.setPassword(cursor.getString(cursor.getColumnIndex("password")));
       account.setMailType(cursor.getString(cursor.getColumnIndex("mailType")));
       account.setEmailAddress(cursor.getString(cursor.getColumnIndex("emailAddress")));
       account.setResId(cursor.getInt(cursor.getColumnIndex("resId")));
       account.setUnReadCount(cursor.getInt(cursor.getColumnIndex("unReadCount")));
       accounts.add(account);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
     db.close();
   }
   return accounts;
 }
Ejemplo n.º 3
0
 public boolean hasMailAccount() {
   String sql = "select count(_id) from t_mail_account";
   SQLiteDatabase db = dbHelper.getReadableDatabase();
   Cursor cursor = null;
   try {
     cursor = db.rawQuery(sql, null);
     int count = 0;
     if (cursor.moveToFirst()) {
       count = cursor.getInt(0);
     }
     if (count > 0) {
       return true;
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
     db.close();
   }
   return false;
 }