Last active
September 17, 2018 07:35
-
-
Save danyashorokh/66ecd49bda9195943a104f1a36722643 to your computer and use it in GitHub Desktop.
[Python] Pymssql db request
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 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