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


Groups > comp.lang.python > #38410

multi-result set MySQLdb queries.

Date 2013-02-07 21:58 +0000
From Andrew Robinson <andrew3@r3dsolutions.com>
Subject multi-result set MySQLdb queries.
Newsgroups comp.lang.python
Message-ID <mailman.1478.1360303259.2939.python-list@python.org> (permalink)

Show all headers | 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