Support for Multiple Statements
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:
- 0.1.4
- Started by
- Geert JM Vanderkelen
- Completed by
- Geert JM Vanderkelen
Related branches
Related bugs
Bug #571201: Problem with more than one statement at a time with cursor.execute() | Fix Released |
Sprints
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(
print cur.fetchone()
cur.next_
print "Inserted rows: %d" % (cur.rowcount)
cur.next_
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.