private void exeSqlInfo(SqlInfo sqlInfo) { if (sqlInfo != null) { debugSql(sqlInfo.getSql()); db.execSQL(sqlInfo.getSql(), sqlInfo.getBindArgsAsArray()); } else { Log.e(TAG, "sava error:sqlInfo is null"); } }
/** * 根据主键查找数据(默认不查询多对一或者一对多的关联数据) * * @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 CursorUtils.getEntity(cursor, clazz, this); } } catch (Exception e) { e.printStackTrace(); } finally { cursor.close(); } } return null; }