setFromBytes method

Future<void> setFromBytes(
  1. dynamic data
)

Set LOB contents from bytes in a single operation

Efficiently replaces the entire LOB contents with the provided data in a single operation. Much faster than multiple write() calls.

For CLOB/NCLOB, provide a String. For BLOB, provide a Uint8List or List<int>.

Example:

// Fast: Single operation
await lob.setFromBytes(largeString);

// Slow: Multiple round trips
for (final chunk in chunks) {
  await lob.write(chunk);
}

Implementation

Future<void> setFromBytes(dynamic data) async {
  _ensureNotDisposed();

  if (_lobType == LobType.blob) {
    if (data is! Uint8List && data is! List<int>) {
      throw OracleException(
        'BLOB setFromBytes requires Uint8List or List<int>, got ${data.runtimeType}',
      );
    }
    await _setFromBytesBlob(data is Uint8List ? data : Uint8List.fromList(data));
  } else if (_lobType == LobType.clob || _lobType == LobType.nclob) {
    if (data is! String) {
      throw OracleException(
        'CLOB/NCLOB setFromBytes requires String, got ${data.runtimeType}',
      );
    }
    await _setFromBytesClob(data);
  } else {
    throw OracleException('Cannot write to BFILE LOB (read-only)');
  }

  // Clear cached size
  _cachedSize = null;
}