fetchOne method

Future<Map<String, dynamic>?> fetchOne()

Fetch a single row

Implementation

Future<Map<String, dynamic>?> fetchOne() async {
  _ensureNotDisposed();

  final columnNames = await _getColumnNames();

  // Fetch next row using pre-allocated buffers
  final fetchResult = _dpiOracle.dpiStmt_fetch(_statement, _foundPtr, _bufferRowIndex);

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

    throw OracleResultSetException(
      'Failed to fetch row',
      errorMessage: errorMsg,
    );
  }

  // Check if no more rows
  if (_foundPtr.value == 0) {
    return null;
  }

  // Build row map
  final row = <String, dynamic>{};

  for (var i = 1; i <= _columnCount; i++) {
    final columnName = columnNames[i - 1];
    final oracleType = _columnOracleTypes![i - 1];
    final value = await _getColumnValue(i, oracleType);
    row[columnName] = value;
  }

  return row;
}