Preql icon indicating copy to clipboard operation
Preql copied to clipboard

OracleInterface not working with TNSNAMES

Open maxfratini opened this issue 1 year ago • 3 comments

Hi,

when a connection uri specify just the TNSNAMES.ORA entry name (e.g. oracle://:@<tnsadmin_entry>), PREQL generates the root error: cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

The problem is due to OracleInterface class that creates a wrong dns in the code at line 225:

...
self.args = dict(dsn="%s/%s" % (host, database), user=user, password=password)
...

In fact, using the TNSNAMES entry only, the host variable contains <tnsadmin_entry>, while the database variable is empty, hence the resulting dsn is corrupted with a trailing "/" that generates the error when the instant client searches the reference in TNSNAMES.ORA

maxfratini avatar Jul 16 '22 14:07 maxfratini

Hi,

Preql doesn't officially support Oracle yet, and you'll encounter all kinds of errors if you try to use it.

But thanks for letting me know! So basically, this should solve it?

dsn = host if database is None else "%s/%s" % (host, database)

erezsh avatar Jul 21 '22 17:07 erezsh

Hi,

I do not believe checking against None would work, because database is set to "". I've fixed this way and it works:

if database == "":
           self.args = dict(dsn="%s" % (host), user=user, password=password)
       else:
           self.args = dict(dsn="%s/%s" % (host, database), user=user, password=password)

maxfratini avatar Jul 21 '22 17:07 maxfratini

I understand. Thanks again.

erezsh avatar Jul 21 '22 17:07 erezsh