I'm trying to query a sqlite3 database to check if a unique user id exists. How it works is the user click the Tkinter button and then inputs their idTag
value. The command reader.read()
is used to get the tag's value. Once the user has inputted their idTag
the datacheck():
function will check the userID column of the database to find a matching idTag
and userID
.
Error Message : sqlite3.InterFaceError: Error binding parameter 0 - probably unsupported type
Note: the idTag
and userID
are SHA-256 hash values
from tkinter import *
import sqlite3 as sql
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
# Tkinter button click Command
def chk():
# Function that handels getting User ID
def tagScanner():
# Get user id value
idTag = reader.read()
# If tag is scanned
if idTag:
# call Database function to check returned idTag
dataCheck(idTag)
return idTag
# Function handles SQLite3 Database
def dataCheck(idTag):
Database = sql.connect('MedaDataBase.db')
# cursor
c = Database.cursor()
# Check if the idTag maches a value in the userID column of sqlite DB
query = 'SELECT userID FROM Users WHERE userID = ?'
c.execute(query, (str(idTag),))
row_returned = c.fetchall()
if id in row_returned == idTag:
# Found a matching row
print('User Verified')
else:
print('Denied')
Database.close()
# Call scanning function
tagScanner()
The datatype of idTag
must be where the problem is, to get rid of it, just change your query to:
c.execute(query, (str(idTag),))
And then instead of using c.fetchone()
use c.fetchall()
and index onto the list and see and choose the necessary data required. Although, I dont think you need indexing because the only data in your database is the single user id, and in such a case, I would not use a database for this, rather just store this data somewhere and do the same checking.