its not something DBAPI has consistent support for, a few backends allow joining of statements with semicolons like SQL server, but for the most prominently used systems like Postgresql and SQLite, it's not generally possible.
The test below illustrates DBAPI support for this feature, only MySQLdb supports it (not OurSQL):
def test(conn, stmt="select 1; select 2"):
cursor = conn.cursor()
try:
cursor.execute(stmt)
print cursor.fetchall()
cursor.nextset()
except Exception, e:
print e
else:
print cursor.fetchall()
import MySQLdb
conn = MySQLdb.connect(user="scott", passwd="tiger", db="test")
print "\nMySQLdb\n---------"
test(conn)
import oursql
conn = oursql.connect(user="scott", passwd="tiger", db="test")
print "\noursql\n---------"
test(conn)
import psycopg2
conn = psycopg2.connect(user="scott", password="tiger", database="test")
print "\npsycopg2\n---------"
test(conn)
import sqlite3
conn = sqlite3.connect(":memory:")
print "\nsqlite\n---------"
test(conn)
import kinterbasdb
conn = kinterbasdb.connect(dsn="/Users/classic/foo.fdb", user="scott", password="tiger")
print "\nfirebird\n--------"
test(conn, "select 1 FROM rdb$database; select 2 FROM rdb$database")
MySQLdb
---------
((1L,),)
((2L,),)
oursql
---------
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select 2' at line 1", None)
psycopg2
---------
[(2,)]
not supported by PostgreSQL
sqlite
---------
You can only execute one statement at a time.
firebird
--------
(-104, 'isc_dsql_prepare: \n Dynamic SQL Error\n SQL error code = -104\n Token unknown - line 1, column 29\n select')
'kinterbasdb.Cursor' object has no attribute 'nextset'