multi-result set MySQLdb queries.

  • Thread starter Andrew Robinson
  • Start date
A

Andrew Robinson

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 = "(e-mail address removed)"
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top