Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41585

Multiple rows from MySQL query saved in an array structure

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <nh.jones01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.028
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'skip:[ 20': 0.03; 'error:': 0.05; 'subject:query': 0.07; 'python': 0.09; 'exception:': 0.09; 'rows': 0.09; 'subject:array': 0.16; 'variable': 0.20; 'work.': 0.23; 'insert': 0.23; 'skip:[ 10': 0.26; "doesn't": 0.28; 'query': 0.30; 'returned': 0.30; 'code': 0.31; "skip:' 20": 0.32; 'null': 0.33; 'to:addr:python-list': 0.33; 'everyone': 0.33; 'code:': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'message- id:@gmail.com': 0.36; 'two': 0.37; 'received:209': 0.37; 'some': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'save': 0.61; 'first': 0.61; 'skip:n 10': 0.63; 'records': 0.68; 'header:Reply- to:1': 0.79; 'reply-to:addr:gmail.com': 0.79; 'header:Return- Path:2': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:to:from:reply-to:subject:message-id:x-priority :x-mailer:mime-version:content-type; bh=JB7vFZ0U4Evv9y2jIc/mPNBDN1p1qyXy+ujg7qEhcNI=; b=cUQ3cc8Nl4TsrWjgIjshrbqoiYhIXNywaCGvxY32MXQvc7CEYexkKQ2GUjq7iAW7Eu cjBuGMIL25FWvuRIwW76/n4nnR8DdPlKEgyCXWS3m8IGK6cbK3zEEPM4L7h6jHnz9tbR UePFCYc5tYvPiAarirujJnJXdXLleFRx7J8QpwZvOgvDTH2AAaD0KSsXqmqUirDfgJ52 eobjWsA4b9gI/o/wZeEzb+OMIYcN+qLpsKep6vHnhQZ37ZXjY5OSEaGi7UcUkhhDb5Jz jjTkrG8Gs5nccNVKOnBor9ZEOPhYsBhOlbC/se04MWIpBmLv54FMWhEZvAx/9DrrPHUa 5bbg==
X-Received by 10.66.102.37 with SMTP id fl5mr8896797pab.170.1363783962687; Wed, 20 Mar 2013 05:52:42 -0700 (PDT)
Date Wed, 20 Mar 2013 12:52:40 +0000
To python-list@python.org
From Norah Jones <nh.jones01@gmail.com>
Subject Multiple rows from MySQL query saved in an array structure
X-Priority 3
X-Mailer CatPHPMailer 5.1 (phpmailer.sourceforge.net)
MIME-Version 1.0
Content-Type multipart/alternative; boundary="b1_afd57caadf8e7c7c1888a7f71f578186"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To Norah Jones <nh.jones01@gmail.com>
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3560.1363783972.2939.python-list@python.org> (permalink)
Lines 68
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363783972 news.xs4all.nl 6973 [2001:888:2000:d::a6]:37234
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41585

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

I  have this Python code:


    self.lock_tables("read", ['nets_permissions as n', 'devices_permissions as d'])
    usrs = self.db.get("SELECT n.user_id FROM nets_permissions as n \
                        left join devices_permissions as d \
                        on n.user_id = d.user_id \
                        where d.user_id is null \
                        and n.network_id=%s and n.perm3", netid)
    self.unlock_tables()
    
    for usr in usrs:
        self.lock_tables("write", ['devices_permissions'])
        self.db.execute("INSERT devices_permissions SET \
                         user_id=%s, network_id=%s, device_id=%s, perm=%s",\
                         usr, netid, sensid, perm)
        self.unlock_tables();

I first do a query to retrieve some user_id from two tables. I want save this user_id in one variable and after do a for loop to insert this records in another table...


    This code doesn't work. I obtain this error:    
    Exception: Multiple rows returned for Database.get() query

How can I retrieve this multiple rows and then process everyone of them at one time?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Multiple rows from MySQL query saved in an array structure Norah Jones <nh.jones01@gmail.com> - 2013-03-20 12:52 +0000

csiph-web