pymonetdb
pymonetdb copied to clipboard
Properly handle multiple result sets
Pymonetdb cannot handle it when you send multiple SQL statements in a single call to Cursor.execute().
For example,
q = """
SELECT value FROM sys.generate_series(0,5);
SELECT value from sys.generate_series(10,15);
"""
cursor.execute(q)
print(cursor.fetchall())
This only yields the result of the second query:
[(10,), (11,), (12,), (13,), (14,)]
More subtly, if the result sets are larger, for example generate_series(0,1000) and generate_series(2000,2000), pymonetdb closes the second result set but not the first result set. The first result set is only dropped when the connection is closed. This can cause the server to run out of storage if the connection is long running, see MonetDB issue 7357.
not having the nextset operator sort of is an hint to the user the multi resultsets aren't support (unfortunately we cannot force single statements).
This has been fixed in release 1.8.0. Pymonetdb now initially returns the first result set rather than the last, and you can use nextset to retrieve the others.