Need wxpython, sqlite3, python help.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 10
Reputation: Megabyte89 is an unknown quantity at this point 
Solved Threads: 0
Megabyte89 Megabyte89 is offline Offline
Newbie Poster

Need wxpython, sqlite3, python help.

 
0
  #1
Oct 26th, 2009
OK I have a search script that suppose to search for information in my database. The problem I having is that I want the user to be able to enter a last name to search.

The only part that is giving me problems is this part, I'm stuck on this part.

  1. db.execute("SElECT fname, lname, phone, address, email from contacts WHERE lname = (results)")

Traceback (most recent call last):
File "C:/Users/Panic/Desktop/Contacts/search.py", line 46, in OnStart
db.execute("SElECT fname, lname, phone, address, email from contacts WHERE lname = (results)")
sqlite3.OperationalError: no such column: results


Here is the rest of the code that I am not having problems with.

  1. #Importing modules
  2.  
  3. import os
  4. import wx
  5. import sqlite3
  6. import Database
  7.  
  8. #Creating a class
  9.  
  10. class search(wx.Frame):
  11. def __init__(self):
  12. wx.Frame.__init__(self, None, -1, 'Search', size = (400,100))
  13. panel = wx.Panel(self, -1)
  14.  
  15. #Centering the frame
  16.  
  17. self.Centre()
  18.  
  19. #Creating input fields
  20.  
  21. searchLabel = wx.StaticText(panel, -1, " Search:")
  22. self.search = wx.TextCtrl(panel, -1, "Enter last name")
  23. searchLabel.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
  24. self.search.SetInsertionPoint(0)
  25.  
  26. #Creating sizers
  27.  
  28. sizer = wx.FlexGridSizer(cols = 8, hgap = 8, vgap = 8)
  29. sizer.AddMany([searchLabel, self.search])
  30. panel.SetSizer(sizer)
  31.  
  32. #Creating buttons and events
  33.  
  34. start = wx.Button(panel, label = 'Start', pos = (225, 0), size = (80, 25))
  35. start.Bind(wx.EVT_BUTTON, self.OnStart, start)
  36.  
  37. results = self.search.GetValue()
  38.  
  39. def OnStart(self, event):
  40. dlg = wx.MessageBox("Start search?", 'Message', wx.YES_NO | wx.ICON_QUESTION)
  41.  
  42. if (dlg == wx.YES):
  43.  
  44. file = open (r'Database.py', 'r')
  45. exec(file.read())
  46. db.execute("SElECT fname, lname, phone, address, email from contacts WHERE lname = (results)")
  47.  
  48.  
  49. else:
  50. self.Destroy()
  51.  
  52.  
  53. if __name__ == '__main__':
  54. myApp = wx.App()
  55. frame = search()
  56. frame.Show()
  57. myApp.MainLoop()

Thanks to anyone who can lend help with this.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,070
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 268
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is
 
0
  #2
Oct 26th, 2009
Originally Posted by Megabyte89 View Post
Thanks to anyone who can lend help with this.
You've simply forgotten to put the value of results into the string. Instead you mistakenly typed the name results. Here's how you should use string formatting to add the value:
  1. db.execute("SElECT fname, lname, phone, address, email from contacts WHERE lname = (%s)" % results)
HTH
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: strider1066 is an unknown quantity at this point 
Solved Threads: 1
strider1066 strider1066 is offline Offline
Newbie Poster
 
0
  #3
Oct 26th, 2009
I believe there may be two problems. Results appears to be undefined within the function. Either pass in results as an argument or use self.results. (The original definition of results should also be made in the method above.

Secondly, the syntax of the pysqlite statement appears to be incorrect try..
  1. db.execute("SElECT fname, lname, phone, address, email from contacts WHERE lname = %s" % self.results)
Reply With Quote Quick reply to this message  
Reply

Tags
python, sqlite, wxpython

Message:




Views: 585 | Replies: 2
Thread Tools Search this Thread



Tag cloud for python, sqlite, wxpython
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC