Kaynağa Gözat

Merge branch 'master' of https://intra.acdp.at/gogs/tanja/cdplib

ogert 5 yıl önce
ebeveyn
işleme
1e01c0b98c

+ 9 - 6
cdplib/db_handlers/SQLHandler.py

@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
 """
 """
 Created on Tue Sep 18 16:20:50 2018
 Created on Tue Sep 18 16:20:50 2018
 
 
@@ -211,13 +209,17 @@ class SQLHandler:
         transaction = connection.begin()
         transaction = connection.begin()
 
 
         errors = []
         errors = []
+        results = []
 
 
         # in the case of multi-query execute each query
         # in the case of multi-query execute each query
         for sub_query in sqlparse.split(query):
         for sub_query in sqlparse.split(query):
             if len(sub_query) > 0:
             if len(sub_query) > 0:
                 try:
                 try:
-                    connection.execute(sub_query, multi=True)
-
+                    result = connection.execute(sub_query)
+                    if result.rowcount > 0:
+                        data = pd.DataFrame(result.fetchall())
+                        data.columns = result.keys()
+                        results.append(data)
                 except Exception as e:
                 except Exception as e:
                     errors.append(str(e))
                     errors.append(str(e))
 
 
@@ -231,6 +233,7 @@ class SQLHandler:
 
 
         transaction.commit()
         transaction.commit()
         connection.close()
         connection.close()
+        return results
 
 
     def execute_query_from_file(self, filename: str):
     def execute_query_from_file(self, filename: str):
         '''
         '''
@@ -441,7 +444,7 @@ class SQLHandler:
                                tablename)
                                tablename)
 
 
             data = self.execute(query)
             data = self.execute(query)
-            colnames = data.columns.tolist()
+            colnames = data[0].columns.tolist()
 
 
         return colnames
         return colnames
 
 
@@ -640,4 +643,4 @@ class SQLHandler:
             self._engine.dispose()
             self._engine.dispose()
         except Exception as e:
         except Exception as e:
             print(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))
             print(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))
-            raise Exception(e)
+            raise Exception(e)

+ 2 - 0
cdplib/db_migration/ParseJsonSchema.py

@@ -355,7 +355,9 @@ class ParseJsonSchema(ParseDbSchema):
         definitions_flag = self._analyze_schema(schema)
         definitions_flag = self._analyze_schema(schema)
 
 
         if definitions_flag:
         if definitions_flag:
+            schema = self._format_schema_for_mongo(schema)
             schema = self._dereference_schema(schema)
             schema = self._dereference_schema(schema)
+            schema = self._format_schema_for_mongo(schema)
 
 
         return schema
         return schema
 
 

+ 2 - 1
setup.py

@@ -8,7 +8,8 @@ INSTALL_REQUIRES = [
         'pymongo',
         'pymongo',
         'jsonref', 
         'jsonref', 
         'simplejson',
         'simplejson',
-        'mysql'
+        'mysql',
+        'sqlalchemy_utils'
 ]
 ]