Retrieving possible list for use in a subsequent INSERT

Nick the Gr33k nikos.gr33k at gmail.com
Thu Oct 31 05:24:14 EDT 2013


====================================
# if first time for webpage; create new record( primary key is 
automatic, hit is defaulted ), if page exists then update record
cur.execute('''INSERT INTO counters (url) VALUES (%s) ON DUPLICATE KEY 
UPDATE hits = hits + 1''', page )
# get the primary key value of the new added record
cID = cur.lastrowid


# 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.append( 'None Yet' )

		
# 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?



More information about the Python-list mailing list