コード例 #1
0
ファイル: LogsDAO.java プロジェクト: 0x4ec7/Logs
 /**
  * @Title: insertNewLog @Description: insert new log to database
  *
  * @param callLog MyCallLog instance
  * @param recordFlagState is record exists
  * @param recordState record storage state
  * @return boolean operation result
  * @throws
  */
 public boolean insertNewLog(
     MyCallLog callLog, RecordFlagState recordFlagState, RecordState recordState) {
   SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
   String sql =
       "INSERT INTO logs (name, number, duration, date, type, uid, record_flag, log_state_flag, record_state_flag) VALUES(?, ?, ?, ?, ?, ?, ?, 0, ?)";
   try {
     db.execSQL(
         sql,
         new Object[] {
           callLog.getName(),
           callLog.getNumber(),
           callLog.getDuration(),
           callLog.getDate(),
           callLog.getCallType().ordinal(),
           Check.getCRC32(callLog),
           recordFlagState.ordinal(),
           recordState.ordinal()
         });
   } catch (SQLException e) {
     e.printStackTrace();
     return false;
   } finally {
     if (db != null && db.isOpen()) {
       db.close();
     }
   }
   return true;
 }
コード例 #2
0
ファイル: LogsDAO.java プロジェクト: 0x4ec7/Logs
  /**
   * @Title: updateLogs @Description: update logs
   *
   * @param callLogs call logs to update
   * @return boolean the result of the operation
   * @throws
   */
  @Deprecated
  public boolean updateLogs(List<MyCallLog> callLogs) {
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
    String sql = "SELECT uid, date FROM logs ORDER BY date";
    Cursor cursor = null;
    try {
      cursor = db.rawQuery(sql, null);

      List<String> uids = new ArrayList<String>();
      // update log_state
      while (cursor.moveToNext()) {
        String uid = cursor.getString(cursor.getColumnIndex("uid"));
        uids.add(uid);
        if (!Utils.containsUid(uid, callLogs)) {
          updateLogState(uid, LogState.ONLY_LOCAL);
        }
      }

      // insert new logs into table
      for (MyCallLog callLog : callLogs) {
        String tmp = Check.getCRC32(callLog);
        if (!uids.contains(tmp)) {
          insertNewLog(callLog);
        }
      }

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    } finally {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      if (db != null && db.isOpen()) {
        db.close();
      }
    }
    return true;
  }