Spaces:
Runtime error
Runtime error
Commit ·
7cf13a6
1
Parent(s): afd022c
separate connection for testsql
Browse files
app.py
CHANGED
|
@@ -88,15 +88,17 @@ eg\n select * from schema.table limit 20\n\n"""
|
|
| 88 |
return sql, disclaimerOutputStripping
|
| 89 |
|
| 90 |
def testSQL(sql):
|
| 91 |
-
global
|
|
|
|
| 92 |
|
| 93 |
sql, disclaimerOutputStripping = preProcessSQL(sql=sql)
|
| 94 |
if not isDataQuery(sql):
|
| 95 |
return "Sorry not allowed to run. As the query modifies the data."
|
| 96 |
try:
|
| 97 |
-
|
| 98 |
-
conn =
|
| 99 |
df = pd.read_sql_query(sql, con=conn)
|
|
|
|
| 100 |
return disclaimerOutputStripping + str(pd.DataFrame(df))
|
| 101 |
except Exception as e:
|
| 102 |
errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
|
|
@@ -106,6 +108,7 @@ def testSQL(sql):
|
|
| 106 |
# modifiedSql = queryHelper.modifySqlQueryEnteredByUser(prompt)
|
| 107 |
# logMessage = {"function":"queryHelper.modifySqlQueryEnteredByUser", "sqlQuery":sql, "modifiedSQLQuery":modifiedSql}
|
| 108 |
# saveLog(logMessage, 'info')
|
|
|
|
| 109 |
return f"The query you entered throws some error. Here is the error. Please try different query\n {str(e)}"
|
| 110 |
|
| 111 |
|
|
|
|
| 88 |
return sql, disclaimerOutputStripping
|
| 89 |
|
| 90 |
def testSQL(sql):
|
| 91 |
+
global dbCreds, queryHelper
|
| 92 |
+
dbEngine2 = DbEngine(dbCreds)
|
| 93 |
|
| 94 |
sql, disclaimerOutputStripping = preProcessSQL(sql=sql)
|
| 95 |
if not isDataQuery(sql):
|
| 96 |
return "Sorry not allowed to run. As the query modifies the data."
|
| 97 |
try:
|
| 98 |
+
dbEngine2.connect()
|
| 99 |
+
conn = dbEngine2.getConnection()
|
| 100 |
df = pd.read_sql_query(sql, con=conn)
|
| 101 |
+
dbEngine2.disconnect()
|
| 102 |
return disclaimerOutputStripping + str(pd.DataFrame(df))
|
| 103 |
except Exception as e:
|
| 104 |
errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
|
|
|
|
| 108 |
# modifiedSql = queryHelper.modifySqlQueryEnteredByUser(prompt)
|
| 109 |
# logMessage = {"function":"queryHelper.modifySqlQueryEnteredByUser", "sqlQuery":sql, "modifiedSQLQuery":modifiedSql}
|
| 110 |
# saveLog(logMessage, 'info')
|
| 111 |
+
dbEngine2.disconnect()
|
| 112 |
return f"The query you entered throws some error. Here is the error. Please try different query\n {str(e)}"
|
| 113 |
|
| 114 |
|