sqlLiteral function

String sqlLiteral(
  1. Object? value
)

Converts a nullable Object to an SQLite literal value.

Only null, String, finite num, and Uint8List values are supported:

  • a null value is converted to "NULL";
  • a String value is escaped and quoted;
  • a finite num is converted via num.toString;
  • a Uint8List value is converted to a quoted hexadecimal representation and is preceded by a single "x" character.

Implementation

String sqlLiteral(Object? value) => switch (value) {
  null => "NULL",
  String _ => quoteWithSingleQuotes(value),
  int _ => value.toString(),
  double _ when value.isFinite => value.toString(),
  Uint8List _ => "x'${hex.encode(value)}'",
  _ => throw StateError("sqlLiteral: $value"),
};