findLibraryPath static method

String findLibraryPath({
  1. String? libraryPath,
})

Find the Oracle client library

Searches in the following order:

  1. Provided libraryPath parameter
  2. ORACLE_CLIENT_LIB_PATH environment variable
  3. Default search paths

Implementation

static String findLibraryPath({String? libraryPath}) {
  // Check provided path first
  if (libraryPath != null && libraryPath.isNotEmpty) {
    if (File(libraryPath).existsSync()) {
      return libraryPath;
    }
    throw OracleConfigurationException(
      'Provided library path does not exist: $libraryPath',
      configKey: 'libraryPath',
    );
  }

  // Check environment variable
  final envPath = Platform.environment['ORACLE_CLIENT_LIB_PATH'];
  if (envPath != null && envPath.isNotEmpty) {
    if (File(envPath).existsSync()) {
      return envPath;
    }
    throw OracleConfigurationException(
      'Library path from environment variable does not exist: $envPath',
      configKey: 'ORACLE_CLIENT_LIB_PATH',
    );
  }

  // Search default paths
  for (final searchPath in getDefaultLibraryPaths()) {
    if (File(searchPath).existsSync()) {
      return searchPath;
    }
  }

  // Not found - provide helpful error message
  final searchedPaths = getDefaultLibraryPaths().join('\n  - ');
  throw OracleConfigurationException(
    'Oracle client library not found. Searched in:\n  - $searchedPaths\n\n'
    'Please either:\n'
    '1. Install Oracle Instant Client\n'
    '2. Set ORACLE_CLIENT_LIB_PATH environment variable\n'
    '3. Provide library path in configuration',
    configKey: 'libraryPath',
  );
}