Nov-15-2021, 02:00 AM
I am not getting an error with a Query but it seems to not recognize WERE clause because it returns every row regardless. See listBy_Loc method below where i pass it a parameter for the Select statement. The parameter indicates it is passed to the Select statement on the debug screen (hover over loc )but regardless of what it is, the query returns ALL. I have four possible Loc entries but have inputted data with just one location present at this time but the sort by the other three locations return ALL rows as well. I have checked the table with DB Browser and know the Loc field has only one location name for all it's entries. does anyone see anything wrong with SELECT statement?
#con=sqlite3.connect('bovine.db'); #c=con.cursor(); #c.execute(""" CREATE TABLE cattleData # (tagNo integer, # Loc text, # sex text, # type text) # """) #c.execute(""" CREATE TABLE locations # (locName text) # """); opList=["Location","Add","Edit"] class MyDataBase: def __init__(self,db_path): self.db_path=db_path def connect(self): self.con=sqlite3.connect(self.db_path) self.c=self.con.cursor() def listBy_Loc(self,loc): self.c.execute('SELECT * FROM cattleData WHERE Loc = loc;') cattle=self.c.fetchall() return cattle def locationList(self): self.c.execute('''SELECT * FROM locations;''') records=self.c.fetchall() return records class MyApp(TabbedPanel): def __init__(self,data_base,myCow): super(MyApp, self).__init__() self.db=data_base self.do_default_tab=False self.myCow=myCow for i in opList: myTPHM=TabbedPanelHeader() myTPHM.text=str(i) self.add_widget(myTPHM) if str(i)=='Location': myTPLoc=TabbedPanel() myTPLoc.do_default_tab=False myTPHM.content=myTPLoc #for j in locList: for row in self.db.locationList(): #self.locationList(): #locationName=str(j) myTPHL=TabbedPanelHeader() myTPHL.text=row[0] myTPLoc.add_widget(myTPHL) stkLoc=StackLayout(orientation='tb-lr',spacing=4) myTPHL.content=stkLoc ### add animals to loc tab for row2 in self.db.listBy_Loc(row[0]): tagNo=row2[0] sex=row2[2] bredBy='Shadow' calfTag='55' Cow=myCow(tagNo,sex,bredBy,calfTag) Cow.bind(on_press=self.cowBtn_Press) # stkLoc.add_widget(Cow) #... if str(i)=='Add': myTPHM.content=self.enterScreen()