getServerVersion method
Get the Oracle Database server version string.
Returns a human-readable version string from the Oracle server. Useful for logging, debugging, and feature compatibility checks.
Returns: A version string like "Oracle Database 19c Enterprise Edition Release 19.0.0.0.0"
Example - Version Logging:
final version = await connection.getServerVersion();
print('Connected to: $version');
// Output: Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0
Example - Feature Compatibility:
final version = await connection.getServerVersion();
if (version.contains('12c') || version.contains('11g')) {
// Use older syntax for legacy databases
await connection.execute('ALTER SESSION SET ...');
} else {
// Use modern features on 18c+
await connection.execute('...');
}
See also:
- getEncodingInfo for character encoding details
Implementation
Future<String> getServerVersion() async {
_ensureConnected();
final versionInfo = _memoryManager.allocate<dpiVersionInfo>(sizeOf<dpiVersionInfo>());
final releaseStringPtr = _memoryManager.allocate<Pointer<Char>>(sizeOf<Pointer<Char>>());
final releaseStringLength = _memoryManager.allocate<Uint32>(sizeOf<Uint32>());
final result = _dpiOracle.dpiConn_getServerVersion(
_connectionPtr.value,
releaseStringPtr,
releaseStringLength,
versionInfo,
);
if (result == DPI_FAILURE) {
throw OracleConnectionException('Failed to get server version');
}
return StringUtils.fromNativeUtf8(releaseStringPtr.value);
}