Skip to content

Instantly share code, notes, and snippets.

@ryanewing
Created April 29, 2014 20:18
Show Gist options
  • Save ryanewing/11410867 to your computer and use it in GitHub Desktop.
Save ryanewing/11410867 to your computer and use it in GitHub Desktop.
pyodbc generator
def rows(cursor, size=5):
while True:
rows = cursor.fetchmany(size)
if not rows:
break
for row in rows:
yield row
connection = pyodbc.connect(driver='{SQL Server Native Client 11.0}',
server='localhost', database='master',
trusted_connection='yes')
sql = 'select name from sys.databases'
cursor = connection.cursor().execute(sql)
for row in rows(cursor):
print row.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment