LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2010, 05:21 AM   #1
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Rep: Reputation: 21
pyqt4 and mysql problem almost solved but not quite


I'm using a text file with a list of int's that I want to read one line at a time and insert into a mysql query (line). It almost works but just reads the same first line over and over.
sample from the input text file:
513121
513017K
513137
515036
513124
510013

error output:

513121
513121, 0
513121
513121, 0
513121
513121, 0
Traceback (most recent call last):
File "Part-Search/inventory.py", line 220, in report
cursor.execute ("SELECT"+" "+line+" "+"description, quantity FROM phppos_items")
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column '513017K' in 'field list'")



my def:
Code:
def report(self):
	inv_file = open("Part-Search/inventory.txt", "r")
	db= MySQLdb.connect(user="root" , passwd="mypass", db="pos")
	while 1:
          lines = inv_file.readlines(100)
	  if not lines:
	     break
          for line in lines:
	   #print line
	   cursor = db.cursor ()
	   #row = cursor.fetchone ()
	   cursor.execute ("SELECT"+" "+line+" "+"description, quantity FROM phppos_items")
	   rows = cursor.fetchall ()
	   for row in rows:
	     print line+"%s, %s" % (row[0], row[1])
	  continue   
	print "Number of rows returned: %d" % cursor.rowcount
	cursor.close ()
	db.close()
Any help would be appreciated!
 
Old 08-22-2010, 11:06 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Suggestion: save your SQL statement to a variable (e.g. "s") and print it out before you call cursor.execute(s). I think the problem will be apparent
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PyQt4 Signals and Slots MTK358 Programming 3 06-20-2010 08:23 PM
SOLVED! MySQL: Change value Kanon Linux - Server 1 04-11-2007 02:58 AM
SOLVED - mysql administrator startup error bking Linux - Software 0 02-10-2005 08:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration