Пример #1
0
 /**
  * 获得所有的查询数据集中的数据
  *
  * @return
  */
 public MapArrayList<String> getQueryCursorData() {
   MapArrayList<String> arrayList = null;
   if (queryCursor != null) {
     try {
       arrayList = new MapArrayList<String>();
       queryCursor.moveToFirst();
       while (queryCursor.moveToNext()) {
         arrayList.add(DBUtils.getRowData(queryCursor));
       }
     } catch (Exception e) {
       e.printStackTrace();
       CHLogger.e(SQLiteDB.this, "当前数据集获取失败!");
     }
   } else {
     CHLogger.e(SQLiteDB.this, "当前数据集不存在!");
   }
   return arrayList;
 }
Пример #2
0
  /**
   * 执行查询,主要是SELECT, SHOW 等指令 返回数据集
   *
   * @param clazz
   * @param distinct 限制重复,如过为true则限制,false则不用管
   * @param where where语句
   * @param groupBy groupBy语句
   * @param having having语句
   * @param orderBy orderBy语句
   * @param limit limit语句
   * @return
   */
  @SuppressWarnings("unchecked")
  public <T> List<T> query(
      Class<?> clazz,
      boolean distinct,
      String where,
      String groupBy,
      String having,
      String orderBy,
      String limit) {

    if (testSQLiteDatabase()) {
      List<T> list = null;
      SqlBuilder getSqlBuilder =
          SqlBuilderFactory.getInstance().getSqlBuilder(SqlBuilderFactory.SELECT);
      getSqlBuilder.setClazz(clazz);
      getSqlBuilder.setCondition(distinct, where, groupBy, having, orderBy, limit);
      try {
        String sqlString = getSqlBuilder.getSqlStatement();
        CHLogger.i(SQLiteDB.this, "执行" + sqlString);
        free();
        this.queryCursor = mSQLiteDatabase.rawQuery(sqlString, null);
        list = (List<T>) DBUtils.getListEntity(clazz, this.queryCursor);
      } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        CHLogger.e(SQLiteDB.this, e.getMessage());
        e.printStackTrace();

      } catch (CHDBException e) {
        // TODO Auto-generated catch block
        CHLogger.e(SQLiteDB.this, e.getMessage());
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        CHLogger.e(SQLiteDB.this, e.getMessage());
        e.printStackTrace();
      }
      return list;
    } else {
      return null;
    }
  }
Пример #3
0
 /**
  * 创建表
  *
  * @param clazz
  * @return 为true创建成功,为false创建失败
  */
 public boolean creatTable(Class<?> clazz) {
   boolean isSuccess = false;
   if (testSQLiteDatabase()) {
     try {
       String sqlString = DBUtils.creatTableSql(clazz);
       execute(sqlString, null);
       isSuccess = true;
     } catch (CHDBException e) {
       // TODO Auto-generated catch block
       isSuccess = false;
       e.printStackTrace();
       CHLogger.e(SQLiteDB.this, e.getMessage());
     } catch (CHDBNotOpenException e) {
       // TODO Auto-generated catch block
       isSuccess = false;
       e.printStackTrace();
       CHLogger.e(SQLiteDB.this, e.getMessage());
     }
   } else {
     CHLogger.e(SQLiteDB.this, "数据库未打开!");
     return false;
   }
   return isSuccess;
 }
Пример #4
0
 public boolean dropTable(Class<?> clazz) {
   String tableName = DBUtils.getTableName(clazz);
   return dropTable(tableName);
 }