mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 17:39:00 +08:00
Fix component exesql bug (#2042)
### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
parent
642006c8e2
commit
f2c4d53c58
@ -274,7 +274,7 @@ class Canvas(ABC):
|
|||||||
def get_embedding_model(self):
|
def get_embedding_model(self):
|
||||||
return self._embed_id
|
return self._embed_id
|
||||||
|
|
||||||
def _find_loop(self, max_loops=2):
|
def _find_loop(self, max_loops=6):
|
||||||
path = self.path[-1][::-1]
|
path = self.path[-1][::-1]
|
||||||
if len(path) < 2: return False
|
if len(path) < 2: return False
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
import re
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from peewee import MySQLDatabase, PostgresqlDatabase
|
from peewee import MySQLDatabase, PostgresqlDatabase
|
||||||
from agent.component.base import ComponentBase, ComponentParamBase
|
from agent.component.base import ComponentBase, ComponentParamBase
|
||||||
@ -59,6 +59,9 @@ class ExeSQL(ComponentBase, ABC):
|
|||||||
|
|
||||||
ans = self.get_input()
|
ans = self.get_input()
|
||||||
ans = "".join(ans["content"]) if "content" in ans else ""
|
ans = "".join(ans["content"]) if "content" in ans else ""
|
||||||
|
ans = re.sub(r'^.*?SELECT ', 'SELECT ', repr(ans), flags=re.IGNORECASE)
|
||||||
|
ans = re.sub(r';.*?SELECT ', '; SELECT ', ans, flags=re.IGNORECASE)
|
||||||
|
ans = re.sub(r';[^;]*$', r';', ans)
|
||||||
if not ans:
|
if not ans:
|
||||||
return ExeSQL.be_output("SQL statement not found!")
|
return ExeSQL.be_output("SQL statement not found!")
|
||||||
|
|
||||||
@ -75,7 +78,7 @@ class ExeSQL(ComponentBase, ABC):
|
|||||||
sql_res = [{"content": rec + "\n"} for rec in [str(i) for i in query.fetchall()]]
|
sql_res = [{"content": rec + "\n"} for rec in [str(i) for i in query.fetchall()]]
|
||||||
db.close()
|
db.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return ExeSQL.be_output("**Error**:" + str(e))
|
return ExeSQL.be_output("**Error**:" + str(e) + "\nError SQL Statement:" + ans)
|
||||||
|
|
||||||
if not sql_res:
|
if not sql_res:
|
||||||
return ExeSQL.be_output("No record in the database!")
|
return ExeSQL.be_output("No record in the database!")
|
||||||
|
@ -175,6 +175,6 @@ def test_db_connect():
|
|||||||
password=req["password"])
|
password=req["password"])
|
||||||
db.connect()
|
db.connect()
|
||||||
db.close()
|
db.close()
|
||||||
return get_json_result(retmsg="Database Connection Successful!")
|
return get_json_result(data="Database Connection Successful!")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return server_error_response(e)
|
return server_error_response(e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user