Python Forum

Full Version: how to compare some string with the database columns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Whenever i run the following code the if statement always returns true and it is not comparing the content with the column content so how can i do this?
How can i check the values with database tables
import pyodbc 

con = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=path of db;')
cr= cn.cursor()
x="something"
y="any"

while True:
    if (cursor.execute('select * from table1 where cm1=(?)',(x)):
        print("success")
        break
    else:
        break
It's not clear to me that cursor objects were meant to resolve as False if no rows were found. Especially since their rowcount attribute is often not set for performance reasons. I would try to fetch the results, and base your conditional on the results.