#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13

    Question Retrieving possible list for use in a subsequent INSERT


    Code:
    # find out if visitor has downloaded torrents in the past
    		cur.execute('''SELECT torrent FROM files WHERE host = %s''', host )
    		data = cur.fetchall()
    
    		downloads = []
    		if data:
    			for torrent in data:
    				downloads.append( torrent )
    		else:
    			downloads = ['Καμία Ακόμη']
    
    		# add this visitor entry into database
    		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''',
    					   (cID, refs, host, city, useros, browser, visits, downloads) )

    Hello,
    In my attempt to add as an extra column key the possible downloads of the current visitor( based on its hostname to identify him) i have wrote the above code to try to do so.

    I'am afraid something its not working as i expect it to work.
    Where is my mistake?

    The error seen form error log is:

    Code:
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] Traceback (most recent call last):
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]   File "/home/nikos/public_html/cgi-bin/metrites.py", line 274, in <module>
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]     (cID, refs, host, city, useros, browser, visits, downloads) )
    
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
    line 274 is:

    # add this visitor entry into database
    cur.execute('''INSERT INTO visitors (counterID, refs, host, city, useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''', (cID, refs, host, city, useros, browser, visits, downloads) )


    This error happened at the moment when i decided to insert the 'downloads' column into the 'visitors' database
    Last edited by Nik; October 31st, 2013 at 08:56 AM.
    What is now proved was once only imagined!
  2. #2
  3. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13

    Question Error when i try try retrive possible list for use in a subsequent INSERT


    Retrieving possible list for use in a subsequent INSERT

    Code:
    		# find out if visitor has downloaded torrents in the past
    		cur.execute('''SELECT torrent FROM files WHERE host = %s''', host )
    		data = cur.fetchall()
    
    		downloads = []
    		if data:
    			for torrent in data:
    				downloads.append( torrent )
    		else:
    			downloads = ['Καμία Ακόμη']
    
    		# add this visitor entry into database
    		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''',
    					   (cID, refs, host, city, useros, browser, visits, downloads) )
    gives me this:

    Code:
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93] Traceback (most recent call last):
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93]   File "/home/nikos/public_html/cgi-bin/metrites.py", line 275, in <module>
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93]     (cID, refs, host, city, useros, browser, visits, downloads) )
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93]   File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 117, in execute
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93]     self.errorhandler(self, exc, value)
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93]   File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/connections.py", line 202, in defaulterrorhandler
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93]     raise errorclass(errorvalue)
    [Thu Oct 31 13:16:00 2013] [error] [client 46.198.103.93] pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
    This error happened at the moment when i decided to insert the 'downloads' column into the 'visitors' database
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo