Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small patch to enable DSN query string for Oracle DBs and others #187

Open
wkvolkman opened this issue Nov 20, 2020 · 1 comment
Open

Small patch to enable DSN query string for Oracle DBs and others #187

wkvolkman opened this issue Nov 20, 2020 · 1 comment

Comments

@wkvolkman
Copy link

Does not seem worth a pull request however I will if that is preferred

--- /home/wkv/anaconda3/lib/python3.7/site-packages/sql/parse.py.orig	2020-09-19 01:41:43.191856384 -0600
+++ /home/wkv/anaconda3/lib/python3.7/site-packages/sql/parse.py	2020-11-19 10:42:20.759017035 -0700
@@ -11,10 +11,12 @@
     parser = CP.ConfigParser()
     parser.read(config.dsn_filename)
     cfg_dict = dict(parser.items(section))
+    if 'query' in cfg_dict and cfg_dict['query'].find('{') >= 0:
+        cfg_dict['query'] = json.loads(cfg_dict['query']) # sqlalchemy requires query to be key value pairs so decode it as json
     return str(URL(**cfg_dict))


-def _connection_string(s):
+def _connection_string(s, config):

     s = expandvars(s)  # for environment variables
     if "@" in s or "://" in s:
@@ -44,7 +46,7 @@
     pieces = cell.split(None, 3)
     if not pieces:
         return result
-    result["connection"] = _connection_string(pieces[0])
+    result["connection"] = _connection_string(pieces[0], config)
     if result["connection"]:
         pieces.pop(0)
     if len(pieces) > 1 and pieces[1] == "<<":
@wkvolkman wkvolkman changed the title Small patch to enable query string for Oracle DBs Small patch to enable DSN query string for Oracle DBs and others Nov 20, 2020
@jlrobins
Copy link

This is a definite bug, and is a reasonable looking fix. sqlalchemy.engine.URL expects 'query' to be a dict; not a string, so tunneling it through the DSN.ini format as a JSON object string is the most straightforward way to go here. Am going to raise a PR with a similar fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants