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. Advertisements

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. Bernard Lebel
    Replies:
    7
    Views:
    464
    Mark Hertel
    Jan 26, 2006
  2. Ian Roddis

    xslt queries in xml to SQL queries

    Ian Roddis, Feb 26, 2006, in forum: Python
    Replies:
    3
    Views:
    1,893
    Crutcher
    Feb 26, 2006
  3. hg

    mysqldb + multi-threading

    hg, Sep 8, 2006, in forum: Python
    Replies:
    7
    Views:
    606
  4. Paul O'Sullivan
    Replies:
    2
    Views:
    1,393
    Lie Ryan
    Nov 29, 2009
  5. BP
    Replies:
    4
    Views:
    245
    Ray at
    Oct 11, 2003
  6. Lord Merlin

    Can multi queries be done in ASP pages?

    Lord Merlin, May 10, 2004, in forum: ASP General
    Replies:
    3
    Views:
    235
    Aaron Bertrand - MVP
    May 10, 2004
  7. Abby Lee

    so many queries within queries I'm confused

    Abby Lee, Aug 4, 2004, in forum: ASP General
    Replies:
    11
    Views:
    627
    Aaron [SQL Server MVP]
    Aug 6, 2004
  8. Michael Tan
    Replies:
    32
    Views:
    1,586
    Ara.T.Howard
    Jul 21, 2005
Loading...