无法在多个数据库上获得结果(SQL-工具)
Unable to get result on multiple databases (SQL-Tools)
我必须从数据库中获取混合结果,但此代码引发错误:
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()
我必须从数据库中获取混合结果,但此代码引发错误:
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()