Created
April 29, 2014 20:18
-
-
Save ryanewing/11410867 to your computer and use it in GitHub Desktop.
pyodbc generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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