erezsh/Preql

OracleInterface not working with TNSNAMES

maxfratini opened this issue · 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

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)

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)

I understand. Thanks again.