Skip to content

Instantly share code, notes, and snippets.

@joellobo
Created March 20, 2017 17:25
Show Gist options
  • Save joellobo/f73fd1a38255d3376d40cedcd386330c to your computer and use it in GitHub Desktop.
Save joellobo/f73fd1a38255d3376d40cedcd386330c to your computer and use it in GitHub Desktop.
1210 | 20/03/17 - 14:05:33 | sudo su
1211 | 20/03/17 - 14:06:25 | sudo apt-get update
1220 | 20/03/17 - 14:11:44 | sudo apt-get install msodbcsql
1221 | 20/03/17 - 14:13:13 | sudo apt-get install mssql-tools
1222 | 20/03/17 - 14:13:28 | sudo apt-get install unixodbc-dev-utf16
1224 | 20/03/17 - 14:15:35 | sudo apt-get install unixODBC-devel
1225 | 20/03/17 - 14:15:54 | sudo apt-get install unixodbc-dev
1226 | 20/03/17 - 14:16:28 | sudo apt-get install gcc-c++
1227 | 20/03/17 - 14:16:36 | sudo apt-get install python-devel
1228 | 20/03/17 - 14:16:59 | sudo pip install pyodbc==3.1.1
1231 | 20/03/17 - 14:17:32 | vim mssql.py
import pyodbc
import sys
server = ''
database = ''
username = ''
password = ''
driver= '{ODBC Driver 13 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute(sys.argv[1])
row = cursor.fetchone()
while row:
print str(row[0]) + " " + str(row[1]) + " " + str(row[2])
row = cursor.fetchone()
1235 | 20/03/17 - 14:20:46 | python mssql.py 'select * from table'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment