Retrieving possible list for use in a subsequent INSERT

Nick the Gr33k nikos.gr33k at gmail.com
Fri Nov 1 16:52:03 CET 2013


Στις 1/11/2013 5:04 μμ, ο/η Nick the Gr33k έγραψε:
> Στις 1/11/2013 12:24 πμ, ο/η Nick the Gr33k έγραψε:
>> Στις 31/10/2013 9:22 μμ, ο/η rurpy at yahoo.com έγραψε:
>>>
>>> You set the value of 'downloads' to a list:
>>>>     downloads = []
>>>>     if data:
>>>>         for torrent in data:
>>>>             downloads.append( torrent )
>>> and when you use 'downloads', use have:
>>>
>>>    INSERT INTO visitors (..., downloads) VALUES (..., %s), (...,
>>> downloads)
>>>
>>> If the 'downloads' column in table 'visitors' is a
>>> normal scalar value (text string or such) then perhaps
>>> you can't insert a value that is a list into it?  And
>>> that may be causing your problem?
>>>
>>> If that is in fact the problem (I am only guessing), you
>>> could convert 'downloads' to a single string for insertion
>>> into your database with something like,
>>>
>>>    downloads = ', '.join( downloads )
>>
>> 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('Καμία Ακόμη'),
>>    foreign key (counterID) references counters(ID),
>>    unique index (visits)
>>   )ENGINE = MYISAM;
>>
>> Decided to declare downlods as  SET column type.
>> and maintain this:
>>
>>          downloads = []
>>          if data:
>>              for torrent in data:
>>                  downloads.append( torrent )
>>
>>
>> but error still is:
>>
>> [Thu Oct 31 22:24:41 2013] [error] [client 46.198.103.93]
>> pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
>
>
> Rurpy can you help me please solve this?
> is enum or set column types what needed here as proper columns to store
> 'download' list?


I can create another table for filenames and use a many to many 
relationship between them because many movies can be downloaded by a 
visitor and many visitors can download a movie.

That could work, but i wish to refrain from creating another mysql 
tabale just to store a couple of movies the visitor could or could not 
download.

Just a mysql column table that will be able to store a list(movies the 
visitor selected) should do.




More information about the Python-list mailing list