Beispiel #1
0
  /**
   * 插入记录
   *
   * @param entity 传入数据实体
   * @param updateFields 插入到的字段,可设置为空
   * @return 返回true执行成功,否则执行失败
   */
  public boolean insert(Object entity, CHArrayList updateFields) {

    SqlBuilder getSqlBuilder =
        SqlBuilderFactory.getInstance().getSqlBuilder(SqlBuilderFactory.INSERT);
    getSqlBuilder.setEntity(entity);
    getSqlBuilder.setUpdateFields(updateFields);
    return execute(getSqlBuilder);
  }
Beispiel #2
0
 /**
  * 删除记录
  *
  * @param entity
  * @return 返回true执行成功,否则执行失败
  */
 public boolean delete(Object entity) {
   if (testSQLiteDatabase()) {
     SqlBuilder getSqlBuilder =
         SqlBuilderFactory.getInstance().getSqlBuilder(SqlBuilderFactory.DELETE);
     getSqlBuilder.setEntity(entity);
     return execute(getSqlBuilder);
   } else {
     return false;
   }
 }
Beispiel #3
0
 /**
  * 更新记录
  *
  * @param entity 更新的数据
  * @param where where语句
  * @return
  */
 public boolean update(Object entity, String where) {
   if (testSQLiteDatabase()) {
     SqlBuilder getSqlBuilder =
         SqlBuilderFactory.getInstance().getSqlBuilder(SqlBuilderFactory.UPDATE);
     getSqlBuilder.setEntity(entity);
     getSqlBuilder.setCondition(false, where, null, null, null, null);
     return execute(getSqlBuilder);
   } else {
     return false;
   }
 }
Beispiel #4
0
 /**
  * 删除记录
  *
  * @param clazz
  * @param where where语句
  * @return 返回true执行成功,否则执行失败
  */
 public boolean delete(Class<?> clazz, String where) {
   if (testSQLiteDatabase()) {
     SqlBuilder getSqlBuilder =
         SqlBuilderFactory.getInstance().getSqlBuilder(SqlBuilderFactory.DELETE);
     getSqlBuilder.setClazz(clazz);
     getSqlBuilder.setCondition(false, where, null, null, null, null);
     return execute(getSqlBuilder);
   } else {
     return false;
   }
 }
Beispiel #5
0
  /**
   * 执行INSERT, UPDATE 以及DELETE操作
   *
   * @param getSqlBuilder Sql语句构建器
   * @return
   */
  public boolean execute(SqlBuilder getSqlBuilder) {
    boolean isSuccess = false;
    String sqlString;
    try {
      sqlString = getSqlBuilder.getSqlStatement();
      execute(sqlString, null);
      isSuccess = true;
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      isSuccess = false;
      e.printStackTrace();

    } catch (CHDBException e) {
      // TODO Auto-generated catch block
      isSuccess = false;
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      isSuccess = false;
      e.printStackTrace();
    } catch (CHDBNotOpenException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      isSuccess = false;
    }
    return isSuccess;
  }
Beispiel #6
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;
    }
  }