read<T> method

T read<T>(
  1. int index,
  2. SqlCodec<T> codec, {
  3. String? expectedName,
})

Decodes the value at index with codec.

When expectedName is present, the actual column label must match it.

Implementation

T read<T>(int index, SqlCodec<T> codec, {String? expectedName}) {
  _checkIndex(index);
  final actualName = _columns[index];
  if (expectedName != null && actualName != expectedName) {
    throw SqlException(
      SqlErrorCode.invalidRow,
      'Column $index is "$actualName", expected "$expectedName".',
    );
  }
  try {
    return codec.decode(_values[index]);
  } on Exception catch (error) {
    throw SqlException(
      SqlErrorCode.invalidRow,
      'Cannot decode column $index ("$actualName").',
      cause: error,
    );
  }
}