multi-result set MySQLdb queries.

Discussion in 'Python' started by Andrew Robinson, Feb 7, 2013.

  1. 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 = ""
    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
     
    Andrew Robinson, Feb 7, 2013
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Roddis

    xslt queries in xml to SQL queries

    Ian Roddis, Feb 26, 2006, in forum: Python
    Replies:
    3
    Views:
    1,531
    Crutcher
    Feb 26, 2006
  2. BP
    Replies:
    4
    Views:
    150
    Ray at
    Oct 11, 2003
  3. Abby Lee

    so many queries within queries I'm confused

    Abby Lee, Aug 4, 2004, in forum: ASP General
    Replies:
    11
    Views:
    367
    Aaron [SQL Server MVP]
    Aug 6, 2004
  4. Michael Tan
    Replies:
    32
    Views:
    1,022
    Ara.T.Howard
    Jul 21, 2005
  5. Dennis Lee Bieber

    Re: multi-result set MySQLdb queries.

    Dennis Lee Bieber, Feb 8, 2013, in forum: Python
    Replies:
    0
    Views:
    134
    Dennis Lee Bieber
    Feb 8, 2013
Loading...

Share This Page