#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,283
    Rep Power
    13

    Question How to add a current string into an already existing list


    Trying to add the current filename into the existent 'downloads' column
    Somehow i don't think i just use the plus sign into an existing column.
    We don't try to add numbers here but add an extra string to an already existing array of strings(list).

    ======================================================
    # update specific torrent's download counter
    cur.execute('''UPDATE files SET hits = hits + 1, host = %s, city = %s, lastvisit = %s WHERE torrent = %s''', (host, city, lastvisit, filename) )

    # update specific visitor's download record
    cur.execute('''UPDATE visitors SET downloads = downloads + %s WHERE host = %s''', (filename, host) )
    ======================================================




    Retrieval time for displaying purposes:
    ======================================================
    downloads = []
    if cur.rowcount:
    for torrent in data:
    downloads = ', '.join( torrent )
    else:
    downloads = 'Κανένα κατέβασμα ταινίας'

    # add this visitor entry into database (visits is 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 this correct, personally i would just prefer:

    for torrent in data:
    downloads.append( torrent )

    Can you tell me the differenced on these two ways?

    Aren't the result of both of them a list?
    What is now proved was once only imagined!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    I don't really get which is your existing list and which is the string you're adding.

    You have: downloads.append( torrent )
    That appends the element, torrent, to the list, downloads.
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,283
    Rep Power
    13
    downloads.append( torrent ) doesnt nto work, it pops the error:

    pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')

    why?
    while downloads = ', '.join( torrent ) doesnr pop an error.

    Trying to add the current filename into the existent 'downloads' column
    Somehow i don't think i just use the plus sign into an existing column.

    i cannot understand why the one works and the other doesn't.

    Also what about this?

    # update specific visitor's download record
    cur.execute('''UPDATE visitors SET downloads = downloads + %s WHERE host = %s''', (filename, host) )

    How
    What is now proved was once only imagined!
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    Something is fishy. <listname>.append(<element>) has nothing to do with SQL. If that's the error you're getting, I don't think it's coming from this statement.

IMN logo majestic logo threadwatch logo seochat tools logo