Skip to content
Advertisement

Sqlite3 in Python not fetching data

I have a sqlite3 DB with a few rows in it. When I try to fetch data from it in Python, fetchall returns an empty list.

  con = sqlite3.connect("commands.db")
  cursor = con.cursor()
  con.execute("SELECT * FROM commands;")
  existing = cursor.fetchall()
  print(existing)
  # Prints []

The data is being inserted in a different part of the project fine. I verified this by opening the DB in “DB Browser for SQLite” and running the following command. This returned the data in the table with no problem.

SELECT * FROM commands;

Has anyone come across a similar issue? Thank you for the help in advance!

Advertisement

Answer

Just change con.execute to cursor.execute. Then it should work

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement