value<T> static method

string value<T>(
  1. T? value, [
  2. bool nullAsBlank = false,
  3. bool quoteStrings = true
])

Implementation

static string value<T>(T? value, [bool nullAsBlank = false, bool quoteStrings = true]) {
  // return a string of this object as a SQL Value
  if (value == null) {
    if (quoteStrings) {
      return nullAsBlank ? "''" : "NULL";
    } else {
      return "";
    }
  } else if (value is Map) {
    return SqlUtil.value(jsonEncode(value), nullAsBlank);
  } else if (value is Iterable) {
    return value.map((e) => SqlUtil.value(e, nullAsBlank, quoteStrings)).join(", ").wrap("(");
  } else if (value is num) {
    return value.toString();
  } else if (value is bool) {
    return value == true ? "1" : "0";
  } else if (value is DateTime) {
    return quoteStrings ? "'${value.toIso8601String()}'" : value.toIso8601String();
  } else {
    string s = changeTo(value);
    if (s.isBlank && nullAsBlank == false) {
      return quoteStrings ? "NULL" : "";
    } else {
      return quoteStrings ? "'${s.replaceAll("'", "''")}'" : s.replaceAll("'", "''");
    }
  }
}