Skip to content

Instantly share code, notes, and snippets.

@danyashorokh
Last active September 17, 2018 07:35
Show Gist options
  • Save danyashorokh/66ecd49bda9195943a104f1a36722643 to your computer and use it in GitHub Desktop.
Save danyashorokh/66ecd49bda9195943a104f1a36722643 to your computer and use it in GitHub Desktop.
[Python] Pymssql db request
def execute_db(host,user,password,db,request):
res = []
conn = pymssql.connect(host, user, password, db)
# print("I AM IN DB!")
cur = conn.cursor()
cur.execute(request)
# res.append([i[0] for i in cur.description]) # columns names
for row in cur:
#print(row)
row = [el.encode('latin1').decode('1251') if el and isinstance(el, str) else el for el in row ] # cyrillic encoding
res.append(row)
conn.close()
# print(request)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment