Sample python programs
During ODBC docker image installation, Python versions 2.7.17 and 3.6.9 and pyodbc library are also installed. This section contains a sample program that you can use to connect to AVZ and execute a query.
Sample program for Python 2.7.17
import pyodbc
conn = pyodbc.connect('DSN=ABCD_DEBUG')
conn.setencoding(unicode,encoding='utf-8', ctype=pyodbc.SQL_CHAR)
conn.setdecoding(pyodbc.SQL_CHAR,encoding='utf-8', ctype=pyodbc.SQL_CHAR)
cursor = conn.cursor()
cursor.execute("select ZIP,CITY,STATE from us_zipcodes limit 10")
for row in cursor:
print(row)
Note: Python 2.7.17 has issues handling in decimal values other than 0-9. For handling decimal
values, use Python 3.6.9.
Sample program for Python 3.6.9
import pyodbc
conn = pyodbc.connect('DSN=ABCD_DEBUG')
conn.setencoding(encoding='utf-8', ctype=pyodbc.SQL_CHAR)
conn.setdecoding(pyodbc.SQL_CHAR,encoding='utf-8', ctype=pyodbc.SQL_CHAR)
cursor = conn.cursor()
cursor.execute("select * from us_zipcodes limit 10")
for row in cursor:
print(row)