getEncodingInfo method

Future<Map<String, dynamic>> getEncodingInfo()

Get character encoding information for this connection.

Returns encoding details including character set IDs and maximum bytes per character. Useful for debugging character encoding issues.

Returns: A map with encoding information:

  • encoding: Character set ID for CHAR/VARCHAR2
  • maxBytesPerCharacter: Max bytes per character (e.g., 4 for AL32UTF8)
  • nencoding: Character set ID for NCHAR/NVARCHAR2
  • nmaxBytesPerCharacter: Max bytes for national character set

Example:

final encoding = await connection.getEncodingInfo();
print('Encoding ID: ${encoding['encoding']}');
print('Max bytes per char: ${encoding['maxBytesPerCharacter']}');
print('National encoding ID: ${encoding['nencoding']}');

// Common encodings:
// AL32UTF8 (UTF-8): maxBytesPerCharacter = 4
// WE8ISO8859P1: maxBytesPerCharacter = 1

See also:

Implementation

Future<Map<String, dynamic>> getEncodingInfo() async {
  _ensureConnected();

  final encoding = _memoryManager.allocate<dpiEncodingInfo>(sizeOf<dpiEncodingInfo>());

  final result = _dpiOracle.dpiConn_getEncodingInfo(
    _connectionPtr.value,
    encoding,
  );

  if (result == DPI_FAILURE) {
    throw OracleConnectionException('Failed to get encoding info');
  }

  return {
    'encoding': StringUtils.fromNativeUtf8(encoding.ref.encoding),
    'maxBytesPerCharacter': encoding.ref.maxBytesPerCharacter,
    'nencoding': StringUtils.fromNativeUtf8(encoding.ref.nencoding),
    'nmaxBytesPerCharacter': encoding.ref.nmaxBytesPerCharacter,
  };
}