Sfoglia il codice sorgente

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

ogert 5 anni fa
parent
commit
1e01c0b98c
3 ha cambiato i file con 13 aggiunte e 7 eliminazioni
  1. 9 6
      cdplib/db_handlers/SQLHandler.py
  2. 2 0
      cdplib/db_migration/ParseJsonSchema.py
  3. 2 1
      setup.py

+ 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
 
@@ -211,13 +209,17 @@ class SQLHandler:
         transaction = connection.begin()
 
         errors = []
+        results = []
 
         # in the case of multi-query execute each query
         for sub_query in sqlparse.split(query):
             if len(sub_query) > 0:
                 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:
                     errors.append(str(e))
 
@@ -231,6 +233,7 @@ class SQLHandler:
 
         transaction.commit()
         connection.close()
+        return results
 
     def execute_query_from_file(self, filename: str):
         '''
@@ -441,7 +444,7 @@ class SQLHandler:
                                tablename)
 
             data = self.execute(query)
-            colnames = data.columns.tolist()
+            colnames = data[0].columns.tolist()
 
         return colnames
 
@@ -640,4 +643,4 @@ class SQLHandler:
             self._engine.dispose()
         except Exception as 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)
 
         if definitions_flag:
+            schema = self._format_schema_for_mongo(schema)
             schema = self._dereference_schema(schema)
+            schema = self._format_schema_for_mongo(schema)
 
         return schema
 

+ 2 - 1
setup.py

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