0

I want to retrieve data from sqlite3 table, this is my code, but I only get an empty list. I checked my query on the sqlite3 and it works fine there.

import sqlite3
conn = sqlite3.connect("testee.db")
c = conn.cursor()
myquery = ("SELECT stock FROM testproduct WHERE store=3;")
c.execute(myquery)
templist=list(c.fetchall())

But templist is empty.

Payam Mesgari
  • 953
  • 1
  • 19
  • 38

2 Answers2

2

instead of extracting the execute statement in list, try this:

    rows=c.fetchall()
    for row in rows:
         print(row)
Naazneen Jatu
  • 526
  • 9
  • 19
-1

I found out the error just now. The database file in that directory was empty. I copied the filled in file to the directory python is running and it works fine.

Payam Mesgari
  • 953
  • 1
  • 19
  • 38