Python Forum
Error Handling/No results from SQL Query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error Handling/No results from SQL Query
#3
Quote: but when the id doesn't exist, I just get an error
Check that row[0] has something in it, i.e. a length
row = cursor.fetchone()
msg="That ID is not found"
if len(row):
    msg="Owner found", "The ADMIN for this problem ID is:  " + row[0])
messagebox.showinfo(msg) 
Note that the SQL server you are using may return None or an error message when not found, so you would then print row to see which not found error condition you should test for.
Reply


Messages In This Thread
RE: Error Handling/No results from SQL Query - by woooee - Jul-18-2018, 12:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculating Average with Error Handling mikasa 5 296 3 hours ago
Last Post: snippsat
Star python exception handling handling .... with traceback mg24 3 1,315 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Help needed with a "for loop" + error handling tamiri 2 2,589 May-27-2022, 12:21 PM
Last Post: tamiri
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,245 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  pymysql: insert query throws error wardancer84 12 4,660 Jan-28-2022, 06:48 AM
Last Post: wardancer84
  Query Syntax Error hammer 2 1,643 Jan-03-2022, 02:30 PM
Last Post: hammer
  Handling Python Fatal Error richajain1785 7 6,002 Oct-14-2021, 01:34 PM
Last Post: Tails86
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,176 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error using mariadb select query with form in python? shams 2 2,040 Jul-29-2021, 12:30 PM
Last Post: shams
  Error Handling JarredAwesome 5 2,999 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome

Forum Jump:

User Panel Messages

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