Support for Multiple Statements

Registered by Geert JM Vanderkelen

We need support for executing multiple statements and getting the results.

Blueprint information

Status:
Complete
Approver:
Geert JM Vanderkelen
Priority:
Medium
Drafter:
Geert JM Vanderkelen
Direction:
Needs approval
Assignee:
Geert JM Vanderkelen
Definition:
Approved
Series goal:
Accepted for trunk
Implementation:
Implemented
Milestone target:
milestone icon 0.1.4
Started by
Geert JM Vanderkelen
Completed by
Geert JM Vanderkelen

Whiteboard

Currently, we support sending Multiple Statements, we don't have anything in place which allows us to go through the multiple results set returned. We'll introduce a new method for the MySQLCursor objects called next_resultset().

Lets have following example in which we do 3 statements, 2 SELECTs and 1 INSERT:

  cur.execute("SELECT * FROM t1; INSERT INTO t1 (c1) VALUES (10),(20); SELECT * FROM t1")
  print cur.fetchone()
  cur.next_resultset()
  print "Inserted rows: %d" % (cur.rowcount)
  cur.next_resultset()
  print cur.fetchall()

Breakdown of the example:

Assuming the table t1 is empty, we get the result:
  print cur.fetchone()

Would give us None, since t1 is empty.
We then get the result of the INSERT statement using next_resultset(). Since this is an INSERT statement, we can't fetch anything from it, however we can get the row count it affected. The output is:

  Inserted rows: 2

The 3rd result set we get by issuing again the next_resultset() which will give us all rows which were inserted using the INSERT statement.

  [(1, 10), (2, 20)]

When you try to get the next result, it will return you None, since there is nothing anymore.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.