Python Forum
how to compare some string with the database columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to compare some string with the database columns
#1
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
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to compare string values in an if statement israelsattleen 1 519 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,116 Jul-02-2021, 02:19 PM
Last Post: xtc14
  convert string into multiple columns in python3 VAN 2 2,724 Sep-26-2020, 11:14 PM
Last Post: scidam
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 4,240 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  Database table structure compare(Oracle) GKT 4 2,674 Oct-16-2019, 03:16 PM
Last Post: GKT
  How to compare string Rehan11 3 2,388 Jan-19-2019, 03:03 PM
Last Post: Rehan11
  Does Python 3.x have a built-in byte string compare function? Raptor88 2 16,306 Feb-18-2017, 10:44 AM
Last Post: Raptor88

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020