Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Last active December 16, 2015 07:19
Show Gist options
  • Select an option

  • Save maltzsama/5397907 to your computer and use it in GitHub Desktop.

Select an option

Save maltzsama/5397907 to your computer and use it in GitHub Desktop.
SqlServer from python with pymssql using Debian or Arch Linux
#!/bin/bash
#Packages
#python, freetds e pymssql
distro=$(lsb_release -a | grep "Distributor ID:")
if [ ${distro:16:6} = "Debian" ]; then
#Install Debian packages
echo "Debian"
apt-get install python freetds-common
apt-get install python-pymssql
elif [ ${distro:16:4} = "arch" ]; then
#Install Arch Linux packages
echo "Arch linux"
pacman -S python freetds
wget -c http://aur.archlinux.org/packages/pymssql/pymssql.tar.gz
tar -xvvzf pymssql.tar.gz
cd pymssql
makepkg PKGBUILD
pacman -U pymssql-0.8.0-1.pkg.tar.gz
else
echo "Distro not supported"
fi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pymssql
conn=pymssql.connect(host='DBSERVER', user='USER', password='PASS', database='DBTESTE')
cur=conn.cursor()
cur.execute("SELECT GETDATE()")
date=cur.fetchone()
print date
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment