Skip to content

Commit 46ea40e

Browse files
committed
Merge branch 'azure-1.11' into azure-2.0
2 parents 0b0bea4 + 8387f95 commit 46ea40e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

sql_server/pyodbc/compiler.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ def _as_sql_variance(self, compiler, connection):
7878
function = '%sP' % function
7979
return self.as_sql(compiler, connection, function=function)
8080

81+
def _cursor_iter(cursor, sentinel, col_count, itersize):
82+
"""
83+
Yields blocks of rows from a cursor and ensures the cursor is closed when
84+
done.
85+
"""
86+
if cursor.db.supports_mars:
87+
# same as the original Django implementation
88+
try:
89+
for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
90+
yield rows if col_count is None else [r[:col_count] for r in rows]
91+
finally:
92+
cursor.close()
93+
else:
94+
# retrieve all chunks from the cursor and close it before yielding
95+
# so that we can open an another cursor over an iteration
96+
# (for drivers such as FreeTDS)
97+
chunks = []
98+
try:
99+
for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
100+
chunks.append(rows if col_count is None else [r[:col_count] for r in rows])
101+
finally:
102+
cursor.close()
103+
for rows in chunks:
104+
yield rows
105+
106+
compiler.cursor_iter = _cursor_iter
107+
81108

82109
class SQLCompiler(compiler.SQLCompiler):
83110

sql_server/pyodbc/features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
88
can_return_id_from_insert = True
99
can_use_chunked_reads = False
1010
for_update_after_from = True
11+
greatest_least_ignores_nulls = True
1112
has_real_datatype = True
1213
has_select_for_update = True
1314
has_select_for_update_nowait = True

0 commit comments

Comments
 (0)