Help me with this code PLEASE

Nick the Gr33k nikos.gr33k at gmail.com
Tue Nov 5 18:06:25 CET 2013


======================================
		# fetch those columns that act as lists but are stored as strings
		cur.execute('''SELECT refs, visits, downloads FROM visitors WHERE 
counterID = %s and host = %s''', (cID, host) )
		data = cur.fetchone()

		ref = visit = download = []
		if cur.rowcount:
			# unpack data into variables
			(ref, visit, download) = data
		
			# retrieve long strings and convert them into lists respectively
			ref = ref.split()
			visit = visit.split()
			download = download.split()
		else:
			# initiate these values
			ref = ref
			visit = lastvisit
			download = ''
		
		refs = visits = downloads = []
		# add current values to each list respectively
		refs.append( ref )
		visits.append( visit )
		downloads.append( download )
		
		# convert lists back to longstrings
		refs = ', '.join( refs )
		visits = ', '.join( visits )
		downloads = ', '.join( downloads )

		# save this visit as an 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)
						ON DUPLICATE KEY UPDATE refs = %s, visits = %s, hits = hits + 1, 
downloads = %s''',
						(cID, refs, host, city, useros, browser, visits, downloads, refs, 
visits, downloads) )
=============================================

IAM STRUGGLING WITH IT 2 DAYS NOW AND I CANNOT GET IT TO WORK.

ALL I WANT IT TO DO IS JUST

1. RETRIEVE 3 COLUMNS THAT CONSIST OF 3 LONG STRINGS
2. CONVERT LONG STRINGS TO LISTS
3. ADD SOME CURRENT VALUES TO THOSE LISTS
4. CONVERT FROM LISTS TO LONG STRINGS SO I CAN STORE SUCCESSFULLY LIST 
PYTHON DATATYPE TO MYSQL SCALAR STRING.

EVERYHTIGN I TRIED FAILED.



More information about the Python-list mailing list