- Code: Select all
# find out if visitor had downloaded torrents in the past
cur.execute('''SELECT torrent FROM files WHERE host = %s''', host )
data = cur.fetchall()
downloads = 
for torrent in data:
downloads.append( torrent )
downloads = 'None Yet'
# add this visitor entry into database (host && downloads are unique)
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) )
If the 'downloads' column in table 'visitors' is a
normal scalar value (text string or such) then perhaps
i cannot insert a value that is a list into it.
From within my python script i need to to store a list variable into a mysql column.
the list is suppose to store torrent filenames in a form of
downloads = ["movie1", "movie2", "movie3", "movie3"]
is enum or set column types what needed here as proper columns to store 'download' list?
create table visitors
counterID integer(5) not null,
host varchar(50) not null,
refs varchar(25) not null,
city varchar(20) not null,
userOS varchar(10) not null,
browser varchar(10) not null,
hits integer(5) not null default 1,
visits datetime not null,
downloads set('None Yet'),
foreign key (counterID) references counters(ID),
unique index (visits)
)ENGINE = MYISAM;
Is the SET column type the way to do it?
i tried it but the error i'm receiving is:
pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
Please help pick the necessary column type that will be able to store a a list of values.