Browse Source

Add functionality for mssql

ogert 3 years ago
parent
commit
890b2d3e2b
1 changed files with 10 additions and 7 deletions
  1. 10 7
      cdplib/db_handlers/SQLHandler.py

+ 10 - 7
cdplib/db_handlers/SQLHandler.py

@@ -66,6 +66,7 @@ class SQLHandler:
             from libraries.configuration import default as cfg
 
             if cfg["SQL"]["DRIVER"]:
+                # TODO : See if this still connect to Mariadb, also try to change to sqlalchemy.engine.url.URL.create
                 db_uri = "{0}://{1}:{2}@{3}:{4}/{5}?driver={}&charset=utf8&local_infile=1"\
                      .format(cfg["SQL"]["SQL_DIALECT"],
                              cfg["SQL"]["SQL_USER"],
@@ -75,13 +76,15 @@ class SQLHandler:
                              cfg["SQL"]["SQL_DATABASE_NAME"],
                              cfg["SQL"]["DRIVER"])
             else:
-                db_uri = "{0}://{1}:{2}@{3}:{4}/{5}?charset=utf8&local_infile=1"\
-                     .format(cfg["SQL"]["SQL_DIALECT"],
-                             cfg["SQL"]["SQL_USER"],
-                             cfg["SQL"]["SQL_PASSWORD"],
-                             cfg["SQL"]["SQL_HOST"],
-                             cfg["SQL"]["SQL_PORT"],
-                             cfg["SQL"]["SQL_DATABASE_NAME"])
+                db_uri = sqlalchemy.engine.url.URL.create(
+                                cfg["SQL"]["SQL_DIALECT"],
+                                username=cfg["SQL"]["SQL_USER"],
+                                password=cfg["SQL"]["SQL_PASSWORD"],
+                                host=cfg["SQL"]["SQL_HOST"],
+                                port=cfg["SQL"]["SQL_PORT"],
+                                database=cfg["SQL"]["SQL_DATABASE_NAME"],
+                                query=dict(driver=cfg["SQL"]["DRIVER"])
+                                )
 
         # assert(isinstance(db_uri, str)),\
         #     "Parameter 'db_uri' must be of type str"