openResource method

Future<void> openResource()

Open the LOB resource for buffered operations

Enables LOB buffering which dramatically improves performance when making multiple write operations. Writes are batched and sent to the database when closeResource() is called or the buffer is full.

Performance Impact: Can improve LOB write performance by 10-50x.

Must call closeResource() to flush buffered writes.

Example:

final lob = await conn.createLob(LobType.clob);
await lob.openResource();
try {
  // Multiple writes are buffered
  await lob.write('Chunk 1');
  await lob.write('Chunk 2');
  await lob.write('Chunk 3');
} finally {
  // Flush all buffered writes
  await lob.closeResource();
}

Implementation

Future<void> openResource() async {
  _ensureNotDisposed();

  if (_resourceOpen) {
    return; // Already open
  }

  final result = _dpiOracle.dpiLob_openResource(_lobPtr);

  if (result == DPI_FAILURE) {
    final errorInfo = _memoryManager.allocate<dpiErrorInfo>(sizeOf<dpiErrorInfo>());
    _dpiOracle.dpiContext_getError(_context, errorInfo);
    final errorMsg = StringUtils.fromNativeUtf8(errorInfo.ref.message.cast<Char>());

    throw OracleException(
      'Failed to open LOB resource',
      errorMessage: errorMsg,
    );
  }

  _resourceOpen = true;
}