0

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

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)

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

4

1 回答 1

0

这是因为当您连接多个数据库时,execute 函数希望您将命令作为 list 列表传递,其中 list 的每个元素是要在每个数据库上执行的命令列表。您可以在文档中阅读更多内容。

更正的代码:

from sql_tools import sqlite

sqlite.connect(["main.db", "base.sqlite3"])
data = sqlite.execute([["SELECT * FROM PREFERENCES"], ["SELECT * FROM USERS"]]).get
sqlite.disconnect()
于 2020-02-19T04:36:01.010 回答