1

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!

2
  • 2
    cursor.execute("SELECT * FROM commands;") with cursor not con. Commented Aug 20, 2021 at 8:55
  • 1
    No need for the semicolon after the SELECT command Commented Aug 20, 2021 at 8:57

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I spent about an hour trying to figure it out. I think I need stronger coffee ☕

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.