FAQ

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

Search Discussions

  • Nick the Gr33k at Nov 1, 2013 at 3:25 pm

    ???? 31/10/2013 9:22 ??, ?/? rurpy at yahoo.com ??????:
    On 10/31/2013 03:24 AM, Nick the Gr33k wrote:
    [...]
    # 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) )
    [...] and
    On 10/31/2013 03:32 AM, Nick the Gr33k wrote:
    The error seen form error log is:

    [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) )

    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 )



    I would like to know if there's a way to store an entire list into a
    MySQL table.
    --
    [code]
       # find out if visitor had 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 = '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) )
    [/code]


    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?


    Code:
    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.
  • Joel Goldstick at Nov 1, 2013 at 3:56 pm

    On Fri, Nov 1, 2013 at 11:25 AM, Nick the Gr33k wrote:
    ???? 31/10/2013 9:22 ??, ?/? rurpy at yahoo.com ??????:
    On 10/31/2013 03:24 AM, Nick the Gr33k wrote:

    [...]
    # 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) )
    [...]

    and
    On 10/31/2013 03:32 AM, Nick the Gr33k wrote:

    The error seen form error log is:

    [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) )


    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 )

    I would like to know if there's a way to store an entire list into a MySQL
    table.
    --
    [code]
    # find out if visitor had 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 = '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) )
    [/code]


    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?

    Code:

    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.
    --
    https://mail.python.org/mailman/listinfo/python-list

    If you have a list of values of the same type, but different values,
    you need a new table with a foreign key to the table it relates to.
    This is a relational database question. You can read more here:


    http://en.wikipedia.org/wiki/Database_normalization#Normal_forms


    --
    Joel Goldstick
    http://joelgoldstick.com
  • Nick the Gr33k at Nov 1, 2013 at 4:00 pm

    ???? 1/11/2013 5:56 ??, ?/? Joel Goldstick ??????:
    On Fri, Nov 1, 2013 at 11:25 AM, Nick the Gr33k wrote:
    ???? 31/10/2013 9:22 ??, ?/? rurpy at yahoo.com ??????:
    On 10/31/2013 03:24 AM, Nick the Gr33k wrote:

    [...]
    # 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) )
    [...]

    and
    On 10/31/2013 03:32 AM, Nick the Gr33k wrote:

    The error seen form error log is:

    [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) )


    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 )

    I would like to know if there's a way to store an entire list into a MySQL
    table.
    --
    [code]
    # find out if visitor had 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 = '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) )
    [/code]


    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?

    Code:

    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.
    --
    https://mail.python.org/mailman/listinfo/python-list
    If you have a list of values of the same type, but different values,
    you need a new table with a foreign key to the table it relates to.
    This is a relational database question. You can read more here:

    http://en.wikipedia.org/wiki/Database_normalization#Normal_forms





    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.
  • Paul Simon at Nov 1, 2013 at 5:07 pm
    "Joel Goldstick" <joel.goldstick@gmail.com> wrote in message
    news:mailman.1935.1383321401.18130.python-list at python.org...
    On Fri, Nov 1, 2013 at 11:25 AM, Nick the Gr33k wrote:
    ???? 31/10/2013 9:22 ??, ?/? rurpy at yahoo.com ??????:
    On 10/31/2013 03:24 AM, Nick the Gr33k wrote:

    [...]
    # 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) )
    [...]

    and
    On 10/31/2013 03:32 AM, Nick the Gr33k wrote:

    The error seen form error log is:

    [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) )


    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 )

    I would like to know if there's a way to store an entire list into a MySQL
    table.
    --
    [code]
    # find out if visitor had 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 = '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) )
    [/code]


    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?

    Code:

    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.
    --
    https://mail.python.org/mailman/listinfo/python-list

    If you have a list of values of the same type, but different values,
    you need a new table with a foreign key to the table it relates to.
    This is a relational database question. You can read more here:


    http://en.wikipedia.org/wiki/Database_normalization#Normal_forms




    --
    Joel Goldstick
    http://joelgoldstick.com


    He doesn't <need> a many to many table, although that would put the schema
    into a classic normal form. Yes, there will be duplicated data. Sometimes
    de-normalizing a schema may make things simpler and easier to use for
    someone not used to database work. I would also use a many to many table
    being familiar with normal forms but it is not a neccessity.


    Paul Simon
  • Nick the Gr33k at Nov 1, 2013 at 5:35 pm

    ???? 1/11/2013 7:07 ??, ?/? Paul Simon ??????:


    If you have a list of values of the same type, but different values,
    you need a new table with a foreign key to the table it relates to.
    This is a relational database question. You can read more here:

    http://en.wikipedia.org/wiki/Database_normalization#Normal_forms

    I already answered to that in my previous post, this answer was Joel's
    there was no need to retype it since i i saw it and responded to it.
  • Paul Simon at Nov 1, 2013 at 7:19 pm
    "Nick the Gr33k" <nikos.gr33k@gmail.com> wrote in message
    news:l50oo5$k05$1 at dont-email.me...
    ???? 1/11/2013 7:07 ??, ?/? Paul Simon ??????:
    If you have a list of values of the same type, but different values,
    you need a new table with a foreign key to the table it relates to.
    This is a relational database question. You can read more here:

    http://en.wikipedia.org/wiki/Database_normalization#Normal_forms
    I already answered to that in my previous post, this answer was Joel's
    there was no need to retype it since i i saw it and responded to it.

    Perhaps you misunderstood my response to Joel's comment. You don't <need> a
    many to many table as he said above in your quote. That's required for a
    normal form but isn't necessary. Denormalize the many to many form, have
    duplicated data in your only table if that works for you. Storage is cheap
    and its easier to create sql stsatements, too.


    Paul Simon
  • Nick the Gr33k at Nov 1, 2013 at 3:52 pm

    ???? 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.
  • Denis McMahon at Nov 1, 2013 at 7:12 pm

    On Thu, 31 Oct 2013 11:32:29 +0200, Nick the Gr33k wrote:


    The error seen form error log is:
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
    pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
    (cID, refs, host, city, useros, browser, visits, downloads) )

    I suspect the issue is that, as a list type, the pysql interface expects
    to map "downloads" to either multiple columns, or one column in multiple
    rows, ie it is expecting the list to deliver multiple data items to the
    database, but the database is looking for a single data item.


    --
    Denis McMahon, denismfmcmahon at gmail.com
  • Nick the Gr33k at Nov 2, 2013 at 12:06 am

    ???? 1/11/2013 9:12 ??, ?/? Denis McMahon ??????:
    On Thu, 31 Oct 2013 11:32:29 +0200, Nick the Gr33k wrote:

    The error seen form error log is:
    [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
    pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
    (cID, refs, host, city, useros, browser, visits, downloads) )
    I suspect the issue is that, as a list type, the pysql interface expects
    to map "downloads" to either multiple columns, or one column in multiple
    rows, ie it is expecting the list to deliver multiple data items to the
    database, but the database is looking for a single data item.



    --
    I wish not to create an extra MySQL table but just have a column that
    can store zero or multiple values within it.


    Shall i use a specific column type like ENUM or SET ?


    i tried it but this also doenst work.


      # find out if visitor had 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 = '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) )


    is the baove code correct?


    downloads is a list(array of multiple values) or even of zero values.


    HOW this 'list' is supposed to get stored into the visitors database?


    What colum is able to handle this list?
  • Denis McMahon at Nov 2, 2013 at 4:41 pm

    On Sat, 02 Nov 2013 02:06:59 +0200, Nick the Gr33k wrote:


    HOW this 'list' is supposed to get stored into the visitors database?
    What colum is able to handle this list?

    A python list is a python datatype. mysql has no equivalent data type to
    a python list. You need to convert your python list into a data element
    or elements that mysql understands.


    The way I would do it would be to use a table for downloads list where
    each download was linked to the visitor who had downloaded it.


    I'm sure all the future users of your torrent search website will be
    pleased to know just how much unnecessary data you are attempting to
    capture about their torrenting activities. When the CIA and the FBI
    persuade the greek government to let them impound your servers, all your
    users worldwide will have their torrenting history laid out in full,
    which I'm sure will please anyone who wishes to litigate against them.


    Note also that Greece is part of the EU and that makes your website
    subject to EU data protection requirements. You have to tell your users
    what data you are collecting and storing, and why you are collecting and
    storing it, and you must destroy the data once it is no longer needed.


    As an observation, if you are simply providing a torrent search engine,
    you do not need to log or record anything at all.


    --
    Denis McMahon, denismfmcmahon at gmail.com
  • Rurpy at Nov 2, 2013 at 2:00 am

    On Friday, November 1, 2013 9:04:08 AM UTC-6, Ferrous Cranus wrote:
    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'd help if I could but I don't use MySql and don't know anything
    about its column types. All I could do it try to read about it
    (which I don't have time for right now) and you know more about
    it than me so you can probably figure it out more quickly.
  • Nick the Gr33k at Nov 2, 2013 at 8:49 am

    ???? 2/11/2013 4:00 ??, ?/? rurpy at yahoo.com ??????:
    On Friday, November 1, 2013 9:04:08 AM UTC-6, Ferrous Cranus wrote:
    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'd help if I could but I don't use MySql and don't know anything
    about its column types. All I could do it try to read about it
    (which I don't have time for right now) and you know more about
    it than me so you can probably figure it out more quickly.



    Okey here is some improvement:


    Splitting the statement in 3 steps to print it before actually executing iy.


    =====
    sql = '''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)
    print repr(sql)
    cur.execute(sql)
    =====


    This the real time values trying to be passed into MySQL table in python
    script's runtime


    =====
    "INSERT INTO visitors (counterID, refs, host, city, useros, browser,
    visits, downloads) VALUES (1, ????? Referrer - ????? Hit,
    46-198-103-93.adsl.cyta.gr, Europe/Athens, Windows, Chrome, 13-11-02
    10:31:29, [('Jobs.2013. WEBRip XViD juggs',),
    ('Pacific.Rim.2013.720p.BDRip.XviD.AC3-ELiTE',), ('Man of Steel 2013
    BRRip XviD AC3-SANTi',), ('Now You See Me EXTENDED 2013 BRRip XviD
    AC3-SANTi',), ('DAS EXPERIMENT (2001) 720p.BDRip.XVID.AC3',), ('Behind
    the Candelabra 2013 BDrip XviD AC3',),
    ('The.Internship.2013.UNRATED.480p.BRRip.Xvid.AC3',), ('Man Of Tai 2013
    WEBrip XVID AC3',), ('Star Trek Into Darkness 2013 BRRip XviD
    AC3-SANTi',), ('ESCAPE PLAN (2013) CAM XViD UNiQUE',)])"


    ProgrammingError(ProgrammingError(1064, "You have an error in your SQL
    syntax; check the manual that corresponds to your MySQL server version
    for the right syntax to use near 'Referrer - ????? Hit,
    46-198-103-93.adsl.cyta.gr, Europe/Athens, Windows, C' at line 1"),)
    =====


    The definition of 'visitro's table is as follows:


    =====
    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,
        download text not null,
        foreign key (counterID) references counters(ID),
        unique index (visits)
       )ENGINE = MYISAM;
    =====


    It is possible to "just" use a VARCHAR or TEXT field and then add
    anything you want to it, including a comma or semi-colon separated list.
  • Nick the Gr33k at Nov 2, 2013 at 10:57 am
    You can see the erro as its appearing here:


    http://superhost.gr/


    Its weird that no single quotes are enclosing the string values though
    and the other bizarre thign is that 'downloads' list is tryign to fiull
    in all the movies.
  • Lele Gaifax at Nov 2, 2013 at 11:32 am

    Nick the Gr33k <nikos.gr33k@gmail.com> writes:


    sql = '''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)

    It was suggested *several* times but I'll reiterate: do not use Python
    iterpolation to pass parameters to your SQL statements, or you sooner or
    later will hit this kind of problems.


    To be clear:

    myvalue = "Italy, Europe"
    mysql = "INSERT INTO sometable (theid, thevalue) VALUES (%s, %s)" % (myid, myvalue)
    print(mysql)
         INSERT INTO sometable (theid, thevalue) VALUES (theid, Italy, Europe)


    ciao, lele.
    --
    nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri
    real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia.
    lele at metapensiero.it | -- Fortunato Depero, 1929.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 1, '13 at 3:04p
activeNov 2, '13 at 4:41p
posts15
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase