oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
307 stars 59 forks source link

Expose service names available in tnsnames.ora #313

Closed mac-vtl closed 1 month ago

mac-vtl commented 3 months ago
  1. Describe your new request in detail

python-oracledb internally parses the content of the tnsnames.ora file here but does not provide or expose a way to list the available service names parsed.

We have use cases where we need to switch between database services. It would be logical to propose the list of available services from the list of services parsed by python-oracledb.

Something like below or similar would work:

from oracledb.connect_params import ConnectParams
params = ConnectParamsImpl()
service_names = params.available_service_names()
# do something with service_names
print(service_names)

Is that something feasible? What are your thoughts?

  1. Give supporting information about tools and operating systems. Give relevant product version numbers
import oracledb
import sys
import platform

print("oracledb.__version__:", oracledb.__version__)
print("platform.platform:", platform.platform())
print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
print("platform.python_version:", platform.python_version())
oracledb.__version__: 2.1.0
platform.platform: Windows-10-10.0.19044-SP0
sys.maxsize > 2**32: True
platform.python_version: 3.11.5
anthony-tuininga commented 3 months ago

Yes, that would be possible and shouldn't be too much effort, either.

anthony-tuininga commented 3 months ago

I have added the function get_network_service_names() which does what you request. If you are able to build from source you can verify that it works for you, too.

mac-vtl commented 3 months ago

not currently setup to build from source but will try to get setup and provide feedback asap. thanks for the quick turnaround.

mac-vtl commented 3 months ago

I can confirm it works as expected. tyvm.

anthony-tuininga commented 1 month ago

This was included in version 2.2.0 which was just released.