Python Forum
Problem with bindnig for query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with bindnig for query
#17
Removing the curly bracjet when it inserted the data was resolved by a small change to 2 lins in each query segment of the code.
Removing the [0] in line 3 and 6 was required. The same was true for each query there after in that segment of code.
try:
    dish_type_entry.delete(0,END)
    index = output.curselection()[0]
    selected = output.get(index)
    c.execute('SELECT Dish_Type FROM Recipes WHERE Recipe = :selected',
    {'selected': selected[0]})
    dish_type_result = c.fetchone()
    dish_type_entry.insert(0,dish_type_result[0])

    recipe_entry.delete(0,END)
    index = output.curselection()[0]
    selected = output.get(index)
    c.execute('SELECT Recipe FROM Recipes WHERE Recipe = :selected',
    {'selected': selected[0]})
    recipe_result = c.fetchone()
    recipe_entry.insert(0,recipe_result[0])

    serves_entry.delete(0,END)
    index = output.curselection()[0]
    selected = output.get(index)
    c.execute('SELECT Serves FROM Recipes WHERE Recipe = :selected',
    {'selected': selected[0]})
    serves_result = c.fetchone()
    serves_entry.insert(0,serves_result[0])

    cook_time_entry.delete(0,END)
    index = output.curselection()[0]
    selected = output.get(index)
    c.execute('SELECT Cook_Time FROM Recipes WHERE Recipe = :selected',
    {'selected': selected[0]})
    cook_time_result = c.fetchone()
    cook_time_entry.insert(0,cook_time_result[0])

    index = output.curselection()[0]
    selected = output.get(index)
    c.execute('SELECT Ingredients FROM Recipes WHERE Recipe = :selected',
    {'selected': selected[0]})
    ingredients_result = c.fetchone()
    ingred.insert(1.0,ingredients_result[0])
    ingred.config(wrap=WORD)

    index = output.curselection()[0]
    selected = output.get(index)
    c.execute('SELECT Instructions FROM Recipes WHERE Recipe = :selected',
    {'selected': selected[0]})
    instructions_result = c.fetchone()
    instruct.insert(1.0, instructions_result[0])
    instruct.config(wrap=WORD)
except:
    messagebox.showerror('DataBase Error', 'Failed to load category')
The resolved code is:
            try:
                dish_type_entry.delete(0,END)
                index = output.curselection()
                selected = output.get(index)
                c.execute('SELECT Dish_Type FROM Recipes WHERE Recipe = :selected',
                {'selected': selected})
                dish_type_result = c.fetchone()
                dish_type_entry.insert(0,dish_type_result[0])

                recipe_entry.delete(0,END)
                index = output.curselection()
                selected = output.get(index)
                c.execute('SELECT Recipe FROM Recipes WHERE Recipe = :selected',
                {'selected': selected})
                recipe_result = c.fetchone()
                recipe_entry.insert(0,recipe_result[0])

                serves_entry.delete(0,END)
                index = output.curselection()
                selected = output.get(index)
                c.execute('SELECT Serves FROM Recipes WHERE Recipe = :selected',
                {'selected': selected})
                serves_result = c.fetchone()
                serves_entry.insert(0,serves_result[0])

                cook_time_entry.delete(0,END)
                index = output.curselection()
                selected = output.get(index)
                c.execute('SELECT Cook_Time FROM Recipes WHERE Recipe = :selected',
                {'selected': selected})
                cook_time_result = c.fetchone()
                cook_time_entry.insert(0,cook_time_result[0])

                index = output.curselection()
                selected = output.get(index)
                c.execute('SELECT Ingredients FROM Recipes WHERE Recipe = :selected',
                {'selected': selected})
                ingredients_result = c.fetchone()
                ingred.insert(1.0,ingredients_result[0])
                ingred.config(wrap=WORD)

                index = output.curselection()
                selected = output.get(index)
                c.execute('SELECT Instructions FROM Recipes WHERE Recipe = :selected',
                {'selected': selected})
                instructions_result = c.fetchone()
                instruct.insert(1.0, instructions_result[0])
                instruct.config(wrap=WORD)
            except:
                messagebox.showerror('DataBase Error', 'Failed to load category')
"Often stumped... But never defeated."
Reply


Messages In This Thread
Problem with bindnig for query - by DT2000 - Mar-08-2019, 03:21 AM
RE: Problem with bindnig for query - by Larz60+ - Mar-08-2019, 03:57 AM
RE: Problem with bindnig for query - by DT2000 - Mar-08-2019, 04:16 AM
RE: Problem with bindnig for query - by Larz60+ - Mar-08-2019, 10:03 AM
RE: Problem with bindnig for query - by DT2000 - Mar-08-2019, 01:51 PM
RE: Problem with bindnig for query - by Larz60+ - Mar-08-2019, 05:13 PM
RE: Problem with bindnig for query - by DT2000 - Mar-09-2019, 02:12 AM
RE: Problem with bindnig for query - by Larz60+ - Mar-09-2019, 09:22 AM
RE: Problem with bindnig for query - by DT2000 - Mar-11-2019, 07:07 PM
RE: Problem with bindnig for query - by DT2000 - Mar-15-2019, 11:06 PM
RE: Problem with bindnig for query - by DT2000 - Mar-18-2019, 02:55 AM
RE: Problem with bindnig for query - by Larz60+ - Mar-18-2019, 09:11 PM
RE: Problem with bindnig for query - by Larz60+ - Mar-19-2019, 02:16 AM
RE: Problem with bindnig for query - by DT2000 - Mar-19-2019, 08:50 AM
RE: Problem with bindnig for query - by DT2000 - Mar-20-2019, 04:46 PM
RE: Problem with bindnig for query - by Larz60+ - Mar-21-2019, 12:49 AM
RE: Problem with bindnig for query - by DT2000 - Mar-21-2019, 01:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem Using SQL Placeholder In MySQL Query AdeS 11 6,137 Jul-31-2021, 12:19 AM
Last Post: Pedroski55
  MySQLdb, problem with query with user-defined variables buran 6 6,413 Feb-03-2017, 06:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

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