Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'causing': 0.04; 'insert': 0.05; 'column': 0.07; 'list?': 0.07; 'problem?': 0.07; 'suppose': 0.07; 'table.': 0.07; 'string': 0.09; 'data:': 0.09; 'filenames': 0.09; 'host,': 0.09; 'insertion': 0.09; 'null,': 0.09; 'type,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'question.': 0.14; '%s,': 0.16; 'columns': 0.16; 'enum': 0.16; 'hits': 0.16; 'nick': 0.16; 'relates': 0.16; 'subject:possible': 0.16; 'index': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'have:': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'script': 0.25; 'references': 0.26; 'skip:" 40': 0.26; 'code:': 0.26; 'downloaded': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'host': 0.29; 'am,': 0.29; 'list:': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'url:wiki': 0.31; 'relational': 0.31; 'url:wikipedia': 0.31; 'values.': 0.31; 'file': 0.32; 'url:python': 0.33; '(most': 0.33; 'fri,': 0.33; 'table': 0.34; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'like,': 0.36; 'url:listinfo': 0.36; 'entry': 0.36; 'url:org': 0.36; 'should': 0.36; 'skip:4 10': 0.37; 'list': 0.37; 'nov': 0.38; 'needed': 0.38; 'files': 0.38; 'fact': 0.38; 'recent': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'read': 0.60; 'new': 0.61; 'browser': 0.61; 'entire': 0.61; 'here:': 0.62; 'email addr:yahoo.com': 0.64; 'pick': 0.64; 'more': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'within': 0.65; 'city': 0.66; 'here': 0.66; 'default': 0.69; '8bit%:92': 0.71; 'foreign': 0.74; 'column.': 0.84; 'visitor': 0.84; 'visits': 0.84; 'joel': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=lstjpn0T/r0cPDirJQwGu0MVWsEwe1ffk+q/hQIkk50=; b=f5Jsm6JoCBAHMfO1T2Bozz7Swk0g8cNJZN1sRbsJGABliwAyyL60tNvRFgRYUb0yhh eFKuPLGpJ0BHNItoJ/d6uVcVtu0r6wbXgbVF4ckD5YlVqNz+QhuvX9641uhpC50TJGwB ZlmlNjbFH+wEpUcihjlotAyxMCfKejU8pPDJXh+4m1dzmVmvmA+ZmWNCBbp5KgpdiwBn 4Ue3dvFisrXwSSE7VkxPhZA51/+sCHDIFOfvt1M5KLL9Tg6qxApmLXJPdDq3OLdGEZR1 l0vpzqJTKWHwrgO/jL1T4KN6Iz/0YgUXgdL6hbfq0a0qWxotl+mok92ocL3SH6UJsfrB GfGA== MIME-Version: 1.0 X-Received: by 10.220.16.73 with SMTP id n9mr2577483vca.24.1383321398221; Fri, 01 Nov 2013 08:56:38 -0700 (PDT) In-Reply-To: References: Date: Fri, 1 Nov 2013 11:56:38 -0400 Subject: Re: Retrieving possible list for use in a subsequent INSERT From: Joel Goldstick To: Nick the Gr33k Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 164 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383321401 news.xs4all.nl 15871 [2001:888:2000:d::a6]:56171 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58279 On Fri, Nov 1, 2013 at 11:25 AM, Nick the Gr33k wro= te: > =CE=A3=CF=84=CE=B9=CF=82 31/10/2013 9:22 =CE=BC=CE=BC, =CE=BF/=CE=B7 rurp= y@yahoo.com =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: >> >> 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 =3D %s''', = host >>> ) >>> data =3D cur.fetchall() >>> >>> downloads =3D [] >>> 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 >>> [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 =3D [] >>> 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 =3D ', '.join( downloads ) >> > > > I would like to know if there's a way to store an entire list into a MySQ= L > table. > -- > [code] > # find out if visitor had downloaded torrents in the past > > cur.execute('''SELECT torrent FROM files WHERE host =3D %= s''', > host ) > data =3D cur.fetchall() > > downloads =3D [] > if data: > for torrent in data: > downloads.append( torrent ) > else: > downloads =3D 'None Yet' > > > # add this visitor entry into database (host && downloads > are unique) > cur.execute('''INSERT INTO visitors (counterID, refs, hos= t, > 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 my= sql > column. > > the list is suppose to store torrent filenames in a form of > > downloads =3D ["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 =3D 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 --=20 Joel Goldstick http://joelgoldstick.com