erezsh / Preql

An interpreted relational query language that compiles to SQL.
Other
616 stars 13 forks source link

OracleInterface not working with TNSNAMES #51

Open maxfratini opened 2 years ago

maxfratini commented 2 years ago

Hi,

when a connection uri specify just the TNSNAMES.ORA entry name (e.g. oracle://user>:<passwd>@<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 , 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

erezsh commented 2 years ago

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)
maxfratini commented 2 years ago

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)
erezsh commented 2 years ago

I understand. Thanks again.