Quellcode durchsuchen

Enable class to use different sql dialects

ogert vor 3 Jahren
Ursprung
Commit
b05d22799c
1 geänderte Dateien mit 5 neuen und 3 gelöschten Zeilen
  1. 5 3
      cdplib/db_handlers/SQLHandler.py

+ 5 - 3
cdplib/db_handlers/SQLHandler.py

@@ -42,7 +42,7 @@ class SQLHandler:
     with different dabase connectors.
     Remark:in each method we force new opening and
     closing of a database connection,
-     this avoids errors when parallelizing with multiprocessing.
+    this avoids errors when parallelizing with multiprocessing.
     '''
     pass
     def __init__(self, db_uri: str = None,
@@ -55,6 +55,7 @@ class SQLHandler:
          sqlalchemy dialects:
              for mysql : mysql+pymysql
              for db2: ibm_db_sa
+             for mssql: mssql+pyodbc
         '''
         from sqlalchemy_utils import database_exists, create_database
 
@@ -64,8 +65,9 @@ class SQLHandler:
 
             from libraries.configuration import default as cfg
 
-            db_uri = "mysql+pymysql://{0}:{1}@{2}:{3}/{4}?charset=utf8&local_infile=1"\
-                     .format(cfg["SQL"]["SQL_USER"],
+            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"],