Hi,
I have made a GUI script, with a textCtrl and have a simple SQL script to run sql queries using mysql. I am trying to take an input as string using stringIO and match it to a string in the sql script. So if the string gets matched exactly, I wish the query below it to be executed. Very simple!
However I have tried writing several methods and techniques to get round this simple matching problem. I am writing a simple program to match fixed strings to fixed sql queries, to give the impression that the computer understands english. Could someone suggest what is wrong below, does the stringIO read properly in python? I'm not sure?
The GUI :
# A button
self.submit = wxButton(panelB, ID_SUBMITBUTTON, ' SUBMIT ', (407,200))
self.submit.SetDefault()
EVT_BUTTON(self, self.submit.GetId(), self.ReadTextCtrl)
#text field
def ReadTextCtrl(self, event):
cursor = connect.cursor(MySQLdb.cursors.DictCursor)
stBuffer = cStringIO.StringIO(self.input.GetValue())
stBuffer.read()
stBuffer.close()
if stBuffer == 'HELLO':
cursor.execute ("SELECT train_id FROM train_timetable")
result_set = cursor.fetchall()
for row in result_set:
print "%s" % (row["train_id"])
print "%d rows were returned" % cursor.rowcount
cursor.close ()
The Sql script:
if stBuffer == 'HELLO':
cursor.execute ("SELECT train_id FROM train_timetable")
result_set = cursor.fetchall()
for row in result_set:
print "%s" % (row["train_id"])
print "%d rows were returned" % cursor.rowcount
cursor.close ()
I will be happy even if the results appear in a DOS window for the meantime!
I am more than willing to send my code if it helps!
Many thanks in adavnce!
···
_________________________________________________________________
Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo