executePreparedNamed method

Future<Uint8List?> executePreparedNamed(
  1. int stmtId,
  2. Map<String, Object?> namedParams,
  3. int timeoutOverrideMs,
  4. int fetchSize, {
  5. int? maxBufferBytes,
})

Executes a prepared statement stmtId using named parameters.

The stmtId must come from prepareNamed. Throws AsyncError with AsyncErrorCode.invalidParameter when named parameter metadata is missing or required parameters are not provided. Repeated placeholders reuse the same value from namedParams.

Implementation

Future<Uint8List?> executePreparedNamed(
  int stmtId,
  Map<String, Object?> namedParams,
  int timeoutOverrideMs,
  int fetchSize, {
  int? maxBufferBytes,
}) async {
  final paramOrder = _namedParamOrderByStmtId[stmtId];
  if (paramOrder == null) {
    throw const AsyncError(
      code: AsyncErrorCode.invalidParameter,
      message: 'Statement was not prepared with prepareNamed',
    );
  }

  try {
    final positional = NamedParameterParser.toPositionalParams(
      namedParams: namedParams,
      paramNames: paramOrder,
    );
    final paramValues = paramValuesFromObjects(positional);
    return executePrepared(
      stmtId,
      paramValues,
      timeoutOverrideMs,
      fetchSize,
      maxBufferBytes: maxBufferBytes,
    );
  } on ParameterMissingException catch (e) {
    throw AsyncError(
      code: AsyncErrorCode.invalidParameter,
      message: e.message,
    );
  }
}