Muhammad Awais
Muhammad Awais

Reputation: 62

Sqlite Select Query with where clause in python return none

My sqlite select query with where clause in python return none or empty (>>> )

import os.path
import sqlite3

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "Dictionary.db")
with sqlite3.connect(db_path) as db:
    t = ('hello',)
    cursor = db.cursor()
    cursor.execute("SELECT * FROM entries Where word=?",t)
    Value = cursor.fetchall()
    for i in Value:
        print (i)        

Output: ( >>> )

But when I use simple select query without where clause it returns all data

Upvotes: 1

Views: 2181

Answers (1)

sixela
sixela

Reputation: 106

Try this query:

cursor.execute("SELECT * FROM entries Where word=?",(t,))

The second argument should be a tuple or a list.

Upvotes: 2

Related Questions