Bläddra i källkod

back to beginning

tsteuer 4 år sedan
förälder
incheckning
b1737b4746
1 ändrade filer med 5 tillägg och 9 borttagningar
  1. 5 9
      cdplib/db_handlers/SQLHandler.py

+ 5 - 9
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,13 @@ class SQLHandler:
         transaction = connection.begin()
 
         errors = []
-        result = []
 
         # in the case of multi-query execute each query
         for sub_query in sqlparse.split(query):
             if len(sub_query) > 0:
                 try:
-                   result.append(pd.read_sql(sql=sub_query, con=connection))
+                    connection.execute(sub_query, multi=True)
+
                 except Exception as e:
                     errors.append(str(e))
 
@@ -228,10 +226,9 @@ class SQLHandler:
 
             self._log.error(err)
             raise Exception(err)
-        
+
         transaction.commit()
         connection.close()
-        return result
 
     def execute_query_from_file(self, filename: str):
         '''
@@ -429,7 +426,7 @@ class SQLHandler:
                         self.read_sql_to_dataframe(query).iloc[:, 0].tolist()]
 
         except Exception as e:
-            self._log.warning((
+            self._log.warn((
                 'Could not select columns from '
                 'informational schema. Trying to '
                 'load the table into a dataframe and selec column names.'
@@ -442,7 +439,7 @@ class SQLHandler:
                                tablename)
 
             data = self.execute(query)
-            colnames = data[0].columns.tolist()
+            colnames = data.columns.tolist()
 
         return colnames
 
@@ -642,4 +639,3 @@ class SQLHandler:
         except Exception as e:
             print(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))
             raise Exception(e)
-