initOracleClient method
Initialize the Oracle client library
Must be called before creating connections or pools. Optionally provide a custom library path.
Implementation
Future<void> initOracleClient({String? libraryPath}) async {
if (_initialized) {
return; // Already initialized
}
try {
// Load the Oracle DPI library
final library = LibraryLoader.loadLibrary(libraryPath: libraryPath);
_dpiOracle = DpiOracle(library);
_memoryManager = MemoryManager();
// Create DPI context
_contextPtr = _memoryManager!.allocate<Pointer<dpiContext>>(sizeOf<Pointer<dpiContext>>());
final errorInfo = _memoryManager!.allocate<dpiErrorInfo>(sizeOf<dpiErrorInfo>());
final result = _dpiOracle!.dpiContext_createWithParams(
DPI_MAJOR_VERSION,
DPI_MINOR_VERSION,
nullptr,
_contextPtr!,
errorInfo,
);
if (result == DPI_FAILURE) {
final errorMsg = StringUtils.fromNativeUtf8(errorInfo.ref.message.cast<Char>());
final errorCode = errorInfo.ref.code;
throw OracleContextException(
'Failed to create Oracle context',
errorCode: errorCode,
errorMessage: errorMsg,
);
}
_context = _contextPtr!.value;
// Get client version
final versionInfo = _memoryManager!.allocate<dpiVersionInfo>(sizeOf<dpiVersionInfo>());
_dpiOracle!.dpiContext_getClientVersion(_context!, versionInfo);
_oracleClientVersion =
'${versionInfo.ref.versionNum}.${versionInfo.ref.releaseNum}.${versionInfo.ref.updateNum}.${versionInfo.ref.portReleaseNum}.${versionInfo.ref.portUpdateNum}';
_oracleClientVersionString = _oracleClientVersion;
_initialized = true;
} catch (e) {
_memoryManager?.dispose();
_memoryManager = null;
_dpiOracle = null;
_contextPtr = null;
_context = null;
if (e is OracleException) {
rethrow;
}
throw OracleContextException('Failed to initialize Oracle client: $e');
}
}