Skip to content
Advertisement

fetchall() not working even with values in database

I am working in python with sqlite3 and I am trying to create a database.

I created a table:

c.execute("CREATE TABLE persoane (nume text, varsta integer, salariu integer)")

Then I added the values into the table:

c.execute("INSERT INTO persoane VALUES('David', 16, 1000)")

When I try to get the values out of the database with fetchall() I get an empty list []

I know the values had been added because I verified it with an online program.

This is the full code for reference:

Advertisement

Answer

You need to execute a query and then use the fetchall(). For example:

Otherwise, you’re not selecting anything from your database, and your c cursor doesn’t know what you want to fetch.

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