gpt4 book ai didi

python - 无法获取多个数据库的结果(SQL 工具)

转载 作者:太空宇宙 更新时间:2023-11-03 19:43:27 25 4
gpt4 key购买 nike

我必须从数据库中获得混合结果,但此代码引发错误:

from sql_tools import sqlite

sqlite.connect(["main.db", "base.sqlite3"])
data = sqlite.execute(["SELECT * FROM PREFERENCES", "SELECT * FROM USERS"]).get
sqlite.disconnect()

错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Hunny\AppData\Local\Programs\Python\Python38\lib\site-packages\sql_tools\sqlite\execute.py", line 28, in execute
obj.execute()
File "C:\Users\Hunny\AppData\Local\Programs\Python\Python38\lib\site-packages\sql_tools\internals.py", line 188, in execute
self.__command = self.__parseCommands()
File "C:\Users\Hunny\AppData\Local\Programs\Python\Python38\lib\site-packages\sql_tools\internals.py", line 270, in __parseCommands
raise e
File "C:\Users\Hunny\AppData\Local\Programs\Python\Python38\lib\site-packages\sql_tools\internals.py", line 260, in __parseCommands
raise exception.UnknownError(
sql_tools.exception.UnknownError: Database and commands are not commuting, n(commands) != n(database)

谁能告诉我如何解决这个问题?

最佳答案

这是因为当您连接多个数据库时,执行函数希望您将命令作为列表列表传递,其中列表的每个元素都是要在每个数据库上执行的命令列表。您可以阅读documentation了解更多信息.

更正的代码:

from sql_tools import sqlite

sqlite.connect(["main.db", "base.sqlite3"])
data = sqlite.execute([["SELECT * FROM PREFERENCES"], ["SELECT * FROM USERS"]]).get
sqlite.disconnect()

关于python - 无法获取多个数据库的结果(SQL 工具),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60293048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com