parseConnectionString method
Parse connection string to extract host, port, and service name
Supports formats:
- Simple: host:port/service_name
- TNS: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=...)(PORT=...))(CONNECT_DATA=(SERVICE_NAME=...)))
Implementation
Map<String, String> parseConnectionString() {
final result = <String, String>{};
// Simple format: host:port/service_name
final simpleRegex = RegExp(r'([^:]+):(\d+)/(.+)');
final simpleMatch = simpleRegex.firstMatch(connectionString);
if (simpleMatch != null) {
result['host'] = simpleMatch.group(1)!;
result['port'] = simpleMatch.group(2)!;
result['service_name'] = simpleMatch.group(3)!;
return result;
}
// TNS format parsing
final hostRegex = RegExp(r'HOST\s*=\s*([^\)]+)', caseSensitive: false);
final portRegex = RegExp(r'PORT\s*=\s*(\d+)', caseSensitive: false);
final serviceRegex =
RegExp(r'SERVICE_NAME\s*=\s*([^\)]+)', caseSensitive: false);
final hostMatch = hostRegex.firstMatch(connectionString);
final portMatch = portRegex.firstMatch(connectionString);
final serviceMatch = serviceRegex.firstMatch(connectionString);
if (hostMatch != null) result['host'] = hostMatch.group(1)!.trim();
if (portMatch != null) result['port'] = portMatch.group(1)!.trim();
if (serviceMatch != null) {
result['service_name'] = serviceMatch.group(1)!.trim();
}
return result;
}