Python Forum
How to use the LIKE clause in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use the LIKE clause in Python
#1
In my app I have a database of dinosaurs. The user types in the name of the dinosaur that they are looking for and it displays information about that particular dinosaur. The problem is that the user might not know the correct spelling of the name of the dinosaur that they are looking for and if the spelling of the name entered into the search box is not correct, it does not display anything. I wrote this same program in another language and used the 'LIKE' clause and if there was a typo, or the name was entered without capitalizing the first letter of the name, it still found the correct record and displayed it. I want to do the same using Python but I can't figure out how Python uses the LIKE clause. If anyone can give me an example I would greatly appreciate it.

Here is the code that I am using:

def searchRec(recNo,e):
     dinoName=searchBox.get()
     conn=sqlite3.connect('dinobase.db')
     c=conn.cursor()
     c.execute('SELECT * FROM dino WHERE name LIKE :dinoName',{'dinoName': dinoName})
     rows=c.fetchall()

     for row in rows:
         recNo = row[0]
         namebox.insert(0, row[1])
         meaningbox.insert(0, row[2])
         pronouncebox.insert(0, row[3])
         periodbox.insert(0, row[4])
         groupbox.insert(0, row[5])
         sizebox.insert(0, row[6])
         livedbox.insert(0, row[7])
         dietbox.insert(0, row[8])
         fossilsbox.insert(0, row[9])
        factfilebox.insert(1.0, row[10])

     c.close()
     conn.close()
Reply


Messages In This Thread
How to use the LIKE clause in Python - by Columbo - Oct-08-2022, 04:15 PM
RE: How to use the LIKE clause in Python - by Yoriz - Oct-08-2022, 04:24 PM
RE: How to use the LIKE clause in Python - by Yoriz - Oct-09-2022, 08:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  SQL Query is not executing WHERE clause hammer 7 2,507 Nov-15-2021, 01:44 PM
Last Post: hammer
  How does this if clause work? Pedroski55 3 2,365 Jun-10-2021, 06:31 AM
Last Post: Gribouillis
  can i raise an exception in a try clause? Skaperen 14 5,972 Dec-19-2019, 12:29 AM
Last Post: Skaperen
  pass captured value from input() to where clause metro17 5 3,400 Sep-09-2019, 05:24 AM
Last Post: metro17
  finally clause Skaperen 6 4,024 Jun-02-2019, 09:02 PM
Last Post: snippsat
  if clause fails DeadCthulhuWaitsDreaming 10 4,935 Apr-07-2019, 09:19 PM
Last Post: DeadCthulhuWaitsDreaming
  how to code in Python "where" clause of SAS FelixS 2 2,888 Mar-26-2019, 04:59 PM
Last Post: FelixS
  break Statements and else Clause on Loops Phytonnewbie 2 2,876 Mar-02-2018, 09:50 AM
Last Post: buran
  My else clause doesn't work (general help) NMW 10 8,184 Jul-17-2017, 01:07 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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