ipython-sql icon indicating copy to clipboard operation
ipython-sql copied to clipboard

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

Open wkvolkman opened this issue 4 years ago • 1 comments

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 avatar Nov 20 '20 05:11 wkvolkman

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.

jlrobins avatar Mar 31 '22 16:03 jlrobins