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


Groups > comp.lang.python > #38410

multi-result set MySQLdb queries.

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrew3@r3dsolutions.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.047
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'prefix': 0.07; 'rows': 0.09; 'subject:set': 0.09; 'bug': 0.10; 'def': 0.10; '"import': 0.16; '(besides': 0.16; 'commented': 0.16; 'contrived': 0.16; 'exception;': 0.16; 'ident': 0.16; 'purposes.': 0.16; 'query,': 0.16; 'code,': 0.18; 'skip:" 40': 0.20; 'trying': 0.21; 'import': 0.21; 'supposed': 0.21; 'back.': 0.22; "python's": 0.23; 'second': 0.24; 'host': 0.24; 'script': 0.24; 'tried': 0.25; 'header:User- Agent:1': 0.26; 'skip:" 20': 0.26; 'executing': 0.27; 'skip:( 20': 0.28; "i'm": 0.29; 'query': 0.30; 'skip:- 10': 0.32; 'getting': 0.33; 'extract': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'another': 0.33; 'skip:- 20': 0.34; 'doing': 0.35; 'there': 0.35; 'but': 0.36; 'two': 0.37; 'being': 0.37; '(for': 0.37; 'data': 0.37; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:-': 0.40; 'identify': 0.61; 'first': 0.61; 'received:phx3.secureserver.net': 0.62; 'received:prod.phx3.secureserver.net': 0.62; 'different': 0.63; 'information': 0.63; 'results': 0.65; 'account': 0.67; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'verification': 0.72; 'transfer': 0.76; 'bulk': 0.78; 'forced': 0.84; 'wrong...': 0.84; '(full': 0.91; 'received:173.201': 0.91
Date Thu, 07 Feb 2013 21:58:46 +0000
From Andrew Robinson <andrew3@r3dsolutions.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120909 Thunderbird/15.0.1
MIME-Version 1.0
To python-list@python.org
Subject multi-result set MySQLdb queries.
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To andrew3@r3dsolutions.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.1478.1360303259.2939.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360303259 news.xs4all.nl 6854 [2001:888:2000:d::a6]:50456
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38410

Show key headers only | View raw


Hi, I'm being forced to use "import MySQLdb" to access a server....and 
am not getting all my data back.

I'm trying to send multiple queries all at once (for time reasons) and 
then extract the rows in bulk.
The queries have different number of columns;  For a contrived example;

script.db.query( '(SELECT Id, password, sessionFlags FROM account WHERE 
Id=(SELECT Id FROM ident where email="%s")); (SELECT * FROM identify);' 
% (prefix) )

resultStore = (script.db.store_result())
     result  = resultStore.fetch_row( maxrows=10 )
     result = str(result) + ":::"+str( resultStore.fetch_row(maxrows=10) )

This ought to return two result sets; and under php -- it does.
The first query, returns 1 row; the second returns 4 rows.

However, when I try to get the results using PYTHON's MySQLdb; I get
((2L, 'abcdefg', 0L),):::()

which is wrong...

I tried doing a "result store" twice, but executing it twice causes an 
exception;
(besides breaking the bulk transfer paradigm that I want ...)

Is this a bug in python/mySQLdb -- or is there another way this is 
supposed to be done?

---------------------------  Appendix (full code, with sensitive 
information foobar'd) -------------------

def m_database():
     global script
     import MySQLdb

     script.db = MySQLdb.connect(
         host = "foo.ipagemysql.com",
           user = "bar",
           passwd = "fooooobar",
         db = "bar"
       )

     prefix = "foobaaaaaaaaarfoo@eggsandspam.commedy.com"
     script.db.query( '(SELECT Id, password, sessionFlags FROM account 
WHERE Id=(SELECT Id FROM identify where email="%s")); (SELECT * FROM 
identify);' % (prefix) )
     # Get the ID number for the account,
     # and then go get the password for verification purposes.
     resultStore = (script.db.store_result())
     result  = resultStore.fetch_row( maxrows=10 )

     # attempt to retrieve second query set
     # resultStore = (script.db.store_result()) # This will cause an 
exception... so commented out.
     result = str(result) + ":::"+str( resultStore.fetch_row(maxrows=10) )

     script.db.close()
     return result

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


Thread

multi-result set MySQLdb queries. Andrew Robinson <andrew3@r3dsolutions.com> - 2013-02-07 21:58 +0000

csiph-web