H Kevin Hu commited on
Commit
5fcb7d4
·
1 Parent(s): cff0ce8

Fix component exesql bug (#2042)

Browse files

### What problem does this PR solve?

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Kevin Hu <[email protected]>

agent/canvas.py CHANGED
@@ -274,7 +274,7 @@ class Canvas(ABC):
274
  def get_embedding_model(self):
275
  return self._embed_id
276
 
277
- def _find_loop(self, max_loops=2):
278
  path = self.path[-1][::-1]
279
  if len(path) < 2: return False
280
 
 
274
  def get_embedding_model(self):
275
  return self._embed_id
276
 
277
+ def _find_loop(self, max_loops=6):
278
  path = self.path[-1][::-1]
279
  if len(path) < 2: return False
280
 
agent/component/exesql.py CHANGED
@@ -14,7 +14,7 @@
14
  # limitations under the License.
15
  #
16
  from abc import ABC
17
-
18
  import pandas as pd
19
  from peewee import MySQLDatabase, PostgresqlDatabase
20
  from agent.component.base import ComponentBase, ComponentParamBase
@@ -59,6 +59,9 @@ class ExeSQL(ComponentBase, ABC):
59
 
60
  ans = self.get_input()
61
  ans = "".join(ans["content"]) if "content" in ans else ""
 
 
 
62
  if not ans:
63
  return ExeSQL.be_output("SQL statement not found!")
64
 
@@ -75,7 +78,7 @@ class ExeSQL(ComponentBase, ABC):
75
  sql_res = [{"content": rec + "\n"} for rec in [str(i) for i in query.fetchall()]]
76
  db.close()
77
  except Exception as e:
78
- return ExeSQL.be_output("**Error**:" + str(e))
79
 
80
  if not sql_res:
81
  return ExeSQL.be_output("No record in the database!")
 
14
  # limitations under the License.
15
  #
16
  from abc import ABC
17
+ import re
18
  import pandas as pd
19
  from peewee import MySQLDatabase, PostgresqlDatabase
20
  from agent.component.base import ComponentBase, ComponentParamBase
 
59
 
60
  ans = self.get_input()
61
  ans = "".join(ans["content"]) if "content" in ans else ""
62
+ ans = re.sub(r'^.*?SELECT ', 'SELECT ', repr(ans), flags=re.IGNORECASE)
63
+ ans = re.sub(r';.*?SELECT ', '; SELECT ', ans, flags=re.IGNORECASE)
64
+ ans = re.sub(r';[^;]*$', r';', ans)
65
  if not ans:
66
  return ExeSQL.be_output("SQL statement not found!")
67
 
 
78
  sql_res = [{"content": rec + "\n"} for rec in [str(i) for i in query.fetchall()]]
79
  db.close()
80
  except Exception as e:
81
+ return ExeSQL.be_output("**Error**:" + str(e) + "\nError SQL Statement:" + ans)
82
 
83
  if not sql_res:
84
  return ExeSQL.be_output("No record in the database!")
api/apps/canvas_app.py CHANGED
@@ -175,6 +175,6 @@ def test_db_connect():
175
  password=req["password"])
176
  db.connect()
177
  db.close()
178
- return get_json_result(retmsg="Database Connection Successful!")
179
  except Exception as e:
180
  return server_error_response(e)
 
175
  password=req["password"])
176
  db.connect()
177
  db.close()
178
+ return get_json_result(data="Database Connection Successful!")
179
  except Exception as e:
180
  return server_error_response(e)