@Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    TextView pesel = (TextView) getView().findViewById(R.id.pesel);
    TextView name = (TextView) getView().findViewById(R.id.name);
    TextView numberOfExams = (TextView) getView().findViewById(R.id.number_of_exams);
    TextView passedExams = (TextView) getView().findViewById(R.id.passed_exams);
    TextView averageResult = (TextView) getView().findViewById(R.id.average_result);

    try {
      final StudentSummary studentSummary =
          dataSource.getStudentSummary(UserActivity.getCurrentPesel());

      /* App is in only one language so let's do a bad thing and leave hardcoded
       * strings. Normally strings should be got from resources and formatted.
       */
      String peselLine = "PESEL: " + studentSummary.getPesel();
      String nameLine = studentSummary.getFirstName() + " " + studentSummary.getSurname();
      String examsNoLine = "Liczba egzaminów: " + studentSummary.getNumberOfExams();
      String passedExamsLine = "Zdane egzaminy: " + studentSummary.getPassedExams();
      String averageLine = "Średni rezultat: " + studentSummary.getAverageResult() + "%";

      pesel.setText(peselLine);
      name.setText(nameLine);
      numberOfExams.setText(examsNoLine);
      passedExams.setText(passedExamsLine);
      averageResult.setText(averageLine);

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemple #2
0
 /**
  * @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;
 }
Exemple #3
0
  /**
   * @Title: updateRecordFlags @Description: check existence of those records, and update record
   * flags in database.
   *
   * @return boolean operation result
   * @throws
   */
  @Deprecated
  public boolean updateRecordFlags() {
    SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
    String sql = "SELECT uid, date, record_flag FROM logs ORDER BY date DESC";
    Cursor cursor = null;
    try {
      cursor = db.rawQuery(sql, null);
      while (cursor.moveToNext()) {
        String uid = cursor.getString(cursor.getColumnIndex("uid"));
        long date = Long.parseLong(cursor.getString(cursor.getColumnIndex("date")));
        int recordFlag = cursor.getInt(cursor.getColumnIndex("record_flag"));

        boolean fileExists = Utils.isFileExists(uid, date);

        if (recordFlag == 0 && fileExists) {
          updateRecordFlag(uid, RecordFlagState.EXIST);
          updateRecordState(uid, RecordState.LOCAL);
        } else if (recordFlag == 1 && !fileExists) {
          updateRecordFlag(uid, RecordFlagState.NOT_EXIST);
        }
      }
    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    } finally {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      if (db != null && db.isOpen()) {
        db.close();
      }
    }
    return true;
  }
 private void deleteAll() {
   try {
     contentResolver.delete(SCTData.SystemConfigDO.WORD_CONTENT_URI, null, null);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Exemple #5
0
  public boolean update(Book book) {
    boolean updated = false;

    try {
      open();

      ContentValues cv = new ContentValues();
      cv.put(DBHelper.KEY_TITLE, book.getTitle());
      cv.put(DBHelper.KEY_AUTHOR, book.getAuthor());

      updated =
          getDB()
                  .update(
                      DBHelper.TABLE_BOOKS,
                      cv,
                      DBHelper.KEY_ID + " = ?",
                      new String[] {String.valueOf(book.getId())})
              > 0;

      close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      close();
    }

    return updated;
  }
  public void insert(ChannelWithTvGuide c) {
    if (db == null) {
      db = getDatabase().getWritableDatabase();
      db.beginTransaction();
    }

    ContentValues values = new ContentValues();
    values.putNull(SQLiteProvider.CHANNEL_TBL_COLUMN_ID);
    values.put(SQLiteProvider.CHANNEL_TBL_COLUMN_KEY, c.getKey());
    values.put(SQLiteProvider.CHANNEL_TBL_COLUMN_TITLE, c.getDescription());

    try {
      long id = db.insert(SQLiteProvider.CHANNEL_TBL_NAME, null, values);

      Collection<TvShow> shows = c.getSortedListing();

      Log.d(TAG, "Channel '" + c.getKey() + "' has " + shows.size() + " shows.");

      for (TvShow show : shows) {
        insert(id, show);
      }
    } catch (SQLException se) {
      Log.d(TAG, se.getMessage());
    }
  }
 public boolean deleteAll() {
   boolean flag = false;
   String deleteHeadSql = "DELETE FROM ProductGroupHead";
   String deleteDetailSql = "DELETE FROM ProductGroupDetail";
   SQLiteDatabase db = AssetsDatabaseManager.getManager().getDatabase();
   try {
     // 开启事务
     db.beginTransaction();
     SQLiteStatement detail_stat = db.compileStatement(deleteDetailSql);
     detail_stat.executeUpdateDelete();
     SQLiteStatement head_stat = db.compileStatement(deleteHeadSql);
     head_stat.executeUpdateDelete();
     // 数据插入成功,设置事物成功标志
     db.setTransactionSuccessful();
     // 保存数据
     db.endTransaction();
     flag = true;
   } catch (SQLException e) {
     // 结束事物,在这里没有设置成功标志,结束后不保存
     ZillionLog.e(this.getClass().getName(), e.getMessage(), e);
     db.endTransaction();
     e.printStackTrace();
   }
   return flag;
 }
 private void setDatosDB(Datos datos) {
   Log.d("db", "Guardando datos en base de datos");
   try {
     database.execSQL("DELETE FROM " + DatosDBHelper.TABLE_DATOS);
     String query =
         "INSERT INTO "
             + DatosDBHelper.TABLE_DATOS
             + " ("
             + DatosDBHelper.COLUMN_NAME
             + ","
             + DatosDBHelper.COLUMN_SURNAME
             + ","
             + DatosDBHelper.COLUMN_DEUDA
             + ")"
             + "VALUES ('"
             + datos.getName()
             + "', '"
             + datos.getSurname()
             + "', '"
             + datos.getDeuda()
             + "');";
     database.execSQL(query);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   database.close();
 }
 /** Close database connection */
 public void close() {
   try {
     db.close();
   } catch (SQLException e) {
     Log.d(TAG, "close exception: " + e.getLocalizedMessage());
   }
 }
    @Override
    protected String doInBackground(HashMap<String, String>... params) {
      HashMap<String, String> arrayListVal = params[0];
      String code = arrayListVal.get(Constants.code);
      String pagenumber = arrayListVal.get(Constants.pagenumber);
      String data = arrayListVal.get(Constants.newsdata);
      String date = arrayListVal.get(Constants.expiry);

      String parentCode = arrayListVal.get(Constants.parentCode);
      long logtimeDate = SystemClock.elapsedRealtime() / 1000;

      // Toast.makeText(getApplicationContext(),
      // logtimeDate+"**"+logtimeDate.getTime(),
      // Toast.LENGTH_SHORT).show();
      databasehandler = DatabaseHandler.getInstance(getApplicationContext());
      try {
        if (databasehandler != null) {
          databasehandler.insertNews(
              code,
              Integer.valueOf(pagenumber),
              data,
              date,
              0,
              String.valueOf(logtimeDate),
              parentCode);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      }
      return parentCode;
    }
Exemple #11
0
 @Override
 public boolean checkNImage(String nImage) {
   boolean isExists = false;
   Cursor cur = null;
   String sql =
       "select count("
           + BaseColumns._ID
           + ") from "
           + FY2Columns.TABLE_NAME
           + " where "
           + FY2Columns.NIMAGE
           + " = ?";
   String[] selectionArgs = {nImage};
   try {
     cur = getSQLiteDatabase().rawQuery(sql, selectionArgs);
     while (cur.moveToNext()) {
       int count = cur.getInt(0);
       if (count > 0) {
         isExists = true;
       }
       break;
     }
   } catch (SQLException ex) {
     Log.e(TAG, "checkNImage failed! - " + ex.getMessage());
   } finally {
     if (cur != null) cur.close();
   }
   return isExists;
 }
 /**
  * 1.insert one row information
  *
  * @param beans
  */
 public void addDownloadTask(ArrayList<DownloadBean> beans) {
   try {
     SQLiteDatabase database = dbHelper.getWritableDatabase();
     for (DownloadBean bean : beans) {
       String sql =
           "insert into download_info(url, file_name, total_size, start_pos, end_pos, compelete_size,"
               + " thread_id, file_version, file_version_code, package_name, icon_url, soft_id, download_id, version_code) values "
               + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
       Object[] bindArgs = {
         bean.url,
         bean.fileName,
         bean.fileSize,
         bean.startPosition,
         bean.endPosition,
         bean.currentPosition,
         bean.threadId,
         bean.fileVersion,
         bean.fileVersionCode,
         bean.packageName,
         bean.iconUrl,
         bean.fileId,
         bean.downloadId,
         bean.versionCode
       };
       database.execSQL(sql, bindArgs);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
 /**
  * 1.insert records
  *
  * @param info
  */
 public void addCompleteTask(DownloadBean info) {
   try {
     SQLiteDatabase database = dbHelper.getWritableDatabase();
     String sql =
         "insert into end_download_info(url, file_name,"
             + " file_size, done_time, icon_url, file_version,"
             + " file_version_code, package_name,"
             + " file_path, soft_id, download_id, version_code) values (?,?,?,?,?,?,?,?,?,?,?,?)";
     Object[] bindArgs = {
       info.url,
       info.fileName,
       info.fileSize,
       info.doneTime,
       info.iconUrl,
       info.fileVersion,
       info.fileVersionCode,
       info.packageName,
       info.savePath,
       info.fileId,
       info.downloadId,
       info.versionCode
     };
     database.execSQL(sql, bindArgs);
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  private void saveAccelerometerDevice(Sensor acc) {
    Cursor accelInfo =
        getContentResolver().query(Accelerometer_Sensor.CONTENT_URI, null, null, null, null);
    if (accelInfo == null || !accelInfo.moveToFirst()) {
      ContentValues rowData = new ContentValues();
      rowData.put(
          Accelerometer_Sensor.DEVICE_ID,
          Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
      rowData.put(Accelerometer_Sensor.TIMESTAMP, System.currentTimeMillis());
      rowData.put(Accelerometer_Sensor.MAXIMUM_RANGE, acc.getMaximumRange());
      rowData.put(Accelerometer_Sensor.MINIMUM_DELAY, acc.getMinDelay());
      rowData.put(Accelerometer_Sensor.NAME, acc.getName());
      rowData.put(Accelerometer_Sensor.POWER_MA, acc.getPower());
      rowData.put(Accelerometer_Sensor.RESOLUTION, acc.getResolution());
      rowData.put(Accelerometer_Sensor.TYPE, acc.getType());
      rowData.put(Accelerometer_Sensor.VENDOR, acc.getVendor());
      rowData.put(Accelerometer_Sensor.VERSION, acc.getVersion());

      try {
        getContentResolver().insert(Accelerometer_Sensor.CONTENT_URI, rowData);

        Intent accel_dev = new Intent(ACTION_AWARE_ACCELEROMETER);
        accel_dev.putExtra(EXTRA_SENSOR, rowData);
        sendBroadcast(accel_dev);

        if (Aware.DEBUG) Log.d(TAG, "Accelerometer device:" + rowData.toString());
      } catch (SQLiteException e) {
        if (Aware.DEBUG) Log.d(TAG, e.getMessage());
      } catch (SQLException e) {
        if (Aware.DEBUG) Log.d(TAG, e.getMessage());
      }
    } else accelInfo.close();
  }
  /**
   * @author Rafeal Piao @Description Store search history in Application
   * @param Context , String
   * @return void
   */
  public void storeHistoryFromServer(
      String uid, Object vid, String content, int colId, int category, String time) {
    try {
      getDb()
          .execSQL(
              "INSERT INTO view_history (UID, VID, CONTENT, COLID, CATEGORY, TIME) "
                  + "VALUES ('"
                  + uid
                  + "',"
                  + vid.toString()
                  + ",'"
                  + content
                  + "',"
                  + colId
                  + ","
                  + category
                  + ",'"
                  + time
                  + "')");

    } catch (SQLException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    closeDB();
  }
 /** @param Id */
 public void deleteCategory(long Id) {
   try {
     db.delete(TABLE_CATEGORIES, "id=" + Id, null);
   } catch (SQLException e) {
     Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage());
   }
 }
  void createTable() {
    SQLiteDatabase db = Obtainer.AcquireDB();
    db.beginTransaction();
    boolean createComplete = false;
    try {
      Obtainer.getDB().execSQL(CREATE);
      createComplete = true;
    } catch (SQLException ex) {
      String msg = null;
      if (ex != null) {
        msg = ex.getMessage();
      }

      if (msg != null && msg.contains("already exists")) {
        createComplete = true;
      } else {
        createComplete = false;
      }
    }
    if (createComplete) {
      db.setTransactionSuccessful();
    }
    db.endTransaction();
    Obtainer.ReleaseDB();
  }
  /**
   * @param Id
   * @return
   */
  public CategoryEntry fetchCategory(long Id) {
    CategoryEntry row = new CategoryEntry();
    try {
      Cursor c =
          db.query(
              true,
              TABLE_CATEGORIES,
              new String[] {"id", "name"},
              "id=" + Id,
              null,
              null,
              null,
              null,
              null);
      if (c.getCount() > 0) {
        c.moveToFirst();
        row.id = c.getLong(0);

        row.name = c.getString(1);
      } else {
        row.id = -1;
        row.name = null;
      }
      c.close();
    } catch (SQLException e) {
      Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage());
    }
    return row;
  }
 private void dropTable(SQLiteDatabase db, String tableName, int oldVersion, int newVersion) {
   try {
     db.execSQL("drop table " + tableName);
   } catch (SQLException se) {
     se.printStackTrace();
   }
 }
 /** @param Id */
 public void deletePassword(long Id) {
   try {
     db.delete(TABLE_PASSWORDS, "id=" + Id, null);
   } catch (SQLException e) {
     Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage());
   }
 }
Exemple #21
0
  public List<BodyLogDto> findAll() {
    Cursor cursor = null;
    try {
      List<BodyLogDto> list = new ArrayList<BodyLogDto>();
      cursor =
          db.query(
              BodyLog.TABLE_NAME,
              COLUMNS,
              null,
              null,
              null,
              null,
              BodyLog.Columns.USER_ID.column());

      if (cursor.moveToFirst()) {
        do {
          list.add(BodyLog.convert(cursor));
        } while (cursor.moveToNext());
      }
      return list;
    } catch (SQLException e) {
      throw new DaoException(DaoException.Error.ERROR, e);
    } finally {
      if (cursor != null) {
        try {
          cursor.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }
 /** Commit all changes since the begin transaction on an open database. */
 public void commit() {
   try {
     db.execSQL("commit;");
   } catch (SQLException e) {
     Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage());
   }
 }
Exemple #23
0
  public List<Book> getAll() {
    List<Book> listBooks = null;

    try {

      open();

      String orderBy = DBHelper.KEY_TITLE + " DESC";

      Cursor c = getDB().query(DBHelper.TABLE_BOOKS, null, null, null, null, null, orderBy);

      if (c.getCount() > 0) {
        listBooks = new ArrayList<Book>();
        while (c.moveToNext()) {
          listBooks.add(CursorToBook(c));
        }
      }

      close();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      close();
    }

    return listBooks;
  }
 /** Rollback all changes since the begin transaction on an open database. */
 public void rollback() {
   try {
     db.execSQL("rollback;");
   } catch (SQLException e) {
     Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage());
   }
 }
  @Override
  public List<Device> getAllDevices() {
    List<Device> devices = null;
    try {
      open();

      devices = new ArrayList<Device>();

      Cursor cursor = db.query(TABLE.ASSET.toString(), null, null, null, null, null, null);

      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {
        Device device = cursorToDevice(cursor);
        devices.add(device);
        cursor.moveToNext();
      }
      cursor.close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      close();
    }

    return devices;
  }
 public void deletePath(String path) {
   try {
     db.delete(DB_TABLE, KEY_PATH + "=?", new String[] {path});
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Exemple #27
0
  /**
   * @Title: getContacts @Description: get contacts
   *
   * @param page page (10 items per page)
   * @return ArrayList<MyContact>
   * @throws
   */
  public ArrayList<MyContact> getContacts(int page) {
    SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
    String sql =
        "SELECT DISTINCT name, number FROM logs WHERE record_state_flag = "
            + RecordState.LOCAL.ordinal()
            + " ORDER BY date DESC limit "
            + (page * 10)
            + ", 10";
    Cursor cursor = null;

    ArrayList<MyContact> contacts = new ArrayList<MyContact>();
    try {
      cursor = db.rawQuery(sql, null);
      while (cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex("name"));
        String number = cursor.getString(cursor.getColumnIndex("number"));
        long date = getLatestContactDate(number);
        int count = getContactCount(number);

        contacts.add(new MyContact(name, number, date, count));
      }

      return contacts;
    } catch (SQLException e) {
      e.printStackTrace();
      return null;
    } finally {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      if (db != null && db.isOpen()) {
        db.close();
      }
    }
  }
    public void onCreate(SQLiteDatabase db) {
      db.execSQL(DB_CREATE);
      Field[] list = R.drawable.class.getFields();
      int count = 0, index = 0;
      for (int i = 0; i < list.length; i++) if (list[i].getName().startsWith("img_")) count++;
      String inner_img_path[] = new String[count];
      for (int i = 0; i < list.length; i++)
        if (list[i].getName().startsWith("img_")) {
          try {
            inner_img_path[index++] = "img_" + list[i].getInt(null);
          } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }

      for (int i = 0; i < count; i++) {
        try {
          String str =
              "INSERT INTO img_path (_id, path) VALUES(" + i + ",'" + inner_img_path[i] + "');";
          db.execSQL(str);
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
Exemple #29
0
  /**
   * @Title: refreshRecords @Description: refresh records in database
   *
   * @return boolean operation result
   * @throws
   */
  public boolean refreshRecords() {
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
    String sql = "SELECT uid, date FROM logs ORDER BY date";
    Cursor cursor = null;
    try {
      cursor = db.rawQuery(sql, null);

      while (cursor.moveToNext()) {
        String uid = cursor.getString(cursor.getColumnIndex("uid"));
        long date = Long.parseLong(cursor.getString(cursor.getColumnIndex("date")));
        if (!Utils.isFileExists(uid, date)) {
          //					updateRecordState(uid, RecordState.DELETED);
          deleteLogByUid(uid);
        }
      }

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    } finally {
      if (cursor != null && !cursor.isClosed()) {
        cursor.close();
      }
      if (db != null && db.isOpen()) {
        db.close();
      }
    }
    return true;
  }
 public void onCreate(SQLiteDatabase db) {
   try {
     db.execSQL(CREATE_TABLE_SQL);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }