fetchDistinctRecords method

Future<Map<String, dynamic>> fetchDistinctRecords({
  1. String condition = "",
  2. String distinctField = "",
  3. String fetchMode = "LIST",
  4. String limitCondition = "",
})

Implementation

Future<Map<String,dynamic>> fetchDistinctRecords({String condition = "",String distinctField = "",String fetchMode = "LIST",String limitCondition = ""}) async {
  Map<String,dynamic> result = {
    "status": "failure",
    "message": "nothing executed",
    "operation": "SELECT"
  };
  try {
    if (distinctField != "") {
      String query =
          "SELECT DISTINCT $distinctField FROM " + getSelectQuery();
      if (condition != "") {
        query += " WHERE " + condition;
      }
      if (limitCondition != "") {
        query += " " + limitCondition;
      }
      Map<String,dynamic >response = await dbHandler.fetchQueryRecords(
          query: query,
          fetchMode: fetchMode,
          formatColumns: getFieldFormats());
      if (response.getString("status").equalsIgnoreCase("success")) {
        result["status"] = "success";
        result["message"] = "record(s) fetched successfully";
        result["records"] = response["records"];
      } else {
        result["message"] = response["message"];
      }
    } else {
      result["message"] = "not specified distinct field";
    }
  } catch (ex, stack) {
    result["message"] = Simplify.getExceptionMessage(ex, stack: stack);
  }
  return result;
}