Home > Enterprise >  Select query returning None
Select query returning None

Time:08-02

Even after inserting few rows in mySql server database, when running select query I am getting result as None.

Here's my code

class Review:
    # Report Display Window
    def reviewReport(self,program):
        if (program!=None):
            print("Not null")
            win = Toplevel(program)
            win.title("New Window")
            win.geometry("626x431")
            style = ttk.Style()
            dbConnection = DbConnection()
            # print(dbConnection.getConnection)
            sqlCursor = dbConnection.getConnection()
            if (dbConnection.getConnection!=None):
                print("Db not null")
                print(sqlCursor)
                print(sqlCursor.execute("SELECT status FROM edp_report"))
                print(sqlCursor.description)
                print("After")
                style.configure("BW.TLabel", foreground="black", background="white")
                l1 = ttk.Label(win,text="Test1", style="BW.TLabel")
                l2 = ttk.Label(win,text="Test", style="BW.TLabel")
                
                l1.pack()
            else:
                print("Null")
        else:
            print("Program null")

And this snapshot from mysql workbench in which I am using the same query there I am able to see rows returned.

mysql workbench

CodePudding user response:

You need to fetch the results after executing the query

sqlCursor.execute("SELECT status FROM edp_report")
results= sqlCursor.fetchall() #use fetchone() if you expect a single result
  • Related