Пример #1
0
 /**
  * 根据主键查找数据(默认不查询多对一或者一对多的关联数据)
  *
  * @param id
  * @param clazz
  */
 public <T> T findById(Object id, Class<T> clazz) {
   checkTableExist(clazz);
   SqlInfo sqlInfo = SqlBuilder.getSelectSqlAsSqlInfo(clazz, id);
   if (sqlInfo != null) {
     debugSql(sqlInfo.getSql());
     Cursor cursor = db.rawQuery(sqlInfo.getSql(), sqlInfo.getBindArgsAsStringArray());
     try {
       if (cursor.moveToNext()) {
         return CursorHelper.getEntity(cursor, clazz, this);
       }
     } catch (Exception e) {
       e.printStackTrace();
     } finally {
       cursor.close();
     }
   }
   return null;
 }