ogert 5 years ago
parent
commit
5d0e3396a3
2 changed files with 40 additions and 8 deletions
  1. 3 7
      cdplib/db_handlers/SQLHandler.py
  2. 37 1
      cdplib/db_migration/ParseMapping.py

+ 3 - 7
cdplib/db_handlers/SQLHandler.py

@@ -216,7 +216,7 @@ class SQLHandler:
             if len(sub_query) > 0:
                 try:
                     result = connection.execute(sub_query)
-                    if result.rowcount > 0:
+                    if result.returns_rows:
                         data = pd.DataFrame(result.fetchall())
                         data.columns = result.keys()
                         results.append(data)
@@ -642,9 +642,5 @@ class SQLHandler:
         try:
             self._engine.dispose()
         except Exception as e:
-            pass
-            #print(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))
-            #raise Exception(e)
-            # Exception occures rather frequently, but doesnt seem to affect the execution of the script
-            # Exception is thrown when trying to dispose of a engine that no longer exists.
-            # The exception has been silenced since no way of seeing if the engine still exists before disposing of it has been found.
+            print(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))
+            raise Exception(e)

+ 37 - 1
cdplib/db_migration/ParseMapping.py

@@ -97,6 +97,42 @@ class ParseMapping:
         '''
         '''
         return self._get_info(key="date_format")
+    
+    def get_internal_names(self) -> dict:
+        '''
+        '''
+ 
+        if all(["internal_name" in d for d in self._mapping]):
+            internal_names = [d["internal_name"] for d in self._mapping]
+    
+        elif all(["internal_name" not in d for d in self._mapping]):
+            internal_names = list(range(len(self._mapping)))
+
+
+        else:
+            err = ("Incorrectly filled mapping. Internal names should "
+                   "either be in all or in neither of the fields")
+            self._log.error(err)
+            raise Exception(err)
+
+        return internal_names
+
+    def get_mongo_names(self) -> dict:
+        '''
+        '''
+        if all(["mongo_name" in d for d in self._mapping]):
+            mongo_names = [d["mongo_name"] for d in self._mapping]
+
+        elif all(["mongo_name" not in d for d in self._mapping]):
+            mongo_names = list(range(len(self._mapping)))
+
+        else:
+            err = ("Incorrectly filled mapping. Mongo names should "
+                   "either be in all or in neither of the fields")
+            self._log.error(err)
+            raise Exception(err)
+
+        return mongo_names
 
     def get_types(self) -> dict:
         '''
@@ -134,7 +170,7 @@ class ParseMapping:
         else:
             err = ("Incorrectly filled mapping. Column numbers should ",
                    "either in all or in neither of the fields")
-            self.log.err(err)
+            self._log.err(err)
             raise Exception(err)
 
         return column_numbers