Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41625
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'error:': 0.05; 'subject:query': 0.07; 'python': 0.09; 'exception:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; '%s,': 0.16; '(%s,': 0.16; 'adapter': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'wed,': 0.16; 'appears': 0.18; 'module': 0.19; 'variable': 0.20; 'import': 0.21; 'implicit': 0.22; 'work.': 0.23; 'insert': 0.23; 'skip:[ 10': 0.26; 'values': 0.26; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'implies': 0.29; 'definition': 0.29; 'probably': 0.29; 'query': 0.30; 'returned': 0.30; 'code': 0.31; 'etc.)': 0.32; "skip:' 20": 0.32; 'null': 0.33; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'everyone': 0.33; 'code:': 0.33; 'equal': 0.33; 'another': 0.33; 'skip:d 20': 0.34; "won't": 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'method': 0.36; 'anything': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'save': 0.61; 'first': 0.61; 'skip:n 10': 0.63; 'records': 0.68; 'user,': 0.69; '*****': 0.84; '2013': 0.84; 'dennis': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: Multiple rows from MySQL query saved in an array structure |
| Date | Wed, 20 Mar 2013 19:38:19 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <abcd1234abc123ab12a0000000141000020000001052@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-76-253-100-117.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 3.3/32.846 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| 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.3577.1363822717.2939.python-list@python.org> (permalink) |
| Lines | 65 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363822717 news.xs4all.nl 6963 [2001:888:2000:d::a6]:43155 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41625 |
Show key headers only | View raw
On Wed, 20 Mar 2013 12:52:40 +0000, Norah Jones <nh.jones01@gmail.com>
declaimed the following in gmane.comp.python.general:
> 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?
What database adapter module are you using... The above sure doesn't
look like MySQLdb... Using MySQLdb's db-api functions the above would
probably look something like (ignoring that your code sample appears to
part of some method in a class):
import MySQLdb as db
con = db.connection(specify DB, user, password, etc.)
cur = con.cursor()
rslt = cur.execute("""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)
***** UHM! "where d.user_id is null" implies (to me) that the join won't
find anything -- n.user_id = d.user_id suggests you want NULL ids on
both sides, but by definition NULL is never equal to NULL!
dta = cur.fetchall()
con.commit() #end implicit transaction
for usr in dta:
cur.execute("""insert devices_permissions
(user_id, network_id, device_id,
perm)
values (%s, %s, %s, %s)""",
(usr, netid, sensid, perm) )
con.commit()
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Multiple rows from MySQL query saved in an array structure Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-03-20 19:38 -0400
csiph-web