Spaces:
Runtime error
Runtime error
Commit ·
751d49e
1
Parent(s): ad66df5
use different connection for running sql query on present data
Browse files
app.py
CHANGED
|
@@ -91,14 +91,16 @@ def testSQL(sql):
|
|
| 91 |
if not isDataQuery(sql):
|
| 92 |
return "Sorry not allowed to run. As the query modifies the data."
|
| 93 |
try:
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
conn =
|
| 97 |
-
df = pd.read_sql_query(sql, con=conn)
|
|
|
|
| 98 |
return disclaimerOutputStripping + str(pd.DataFrame(df))
|
| 99 |
except Exception as e:
|
| 100 |
errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
|
| 101 |
saveLog(errorMessage, 'error')
|
|
|
|
| 102 |
|
| 103 |
print(f"Error occured during running the query {sql}.\n and the error is {str(e)}")
|
| 104 |
|
|
|
|
| 91 |
if not isDataQuery(sql):
|
| 92 |
return "Sorry not allowed to run. As the query modifies the data."
|
| 93 |
try:
|
| 94 |
+
dbEngine2 = DbEngine(dbCreds)
|
| 95 |
+
dbEngine2.connect()
|
| 96 |
+
conn = dbEngine2.getConnection()
|
| 97 |
+
df = pd.read_sql_query(sql, con=conn)
|
| 98 |
+
dbEngine2.disconnect()
|
| 99 |
return disclaimerOutputStripping + str(pd.DataFrame(df))
|
| 100 |
except Exception as e:
|
| 101 |
errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
|
| 102 |
saveLog(errorMessage, 'error')
|
| 103 |
+
dbEngine2.disconnect()
|
| 104 |
|
| 105 |
print(f"Error occured during running the query {sql}.\n and the error is {str(e)}")
|
| 106 |
|