-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSSQL.py
More file actions
50 lines (38 loc) · 1.14 KB
/
MSSQL.py
File metadata and controls
50 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pymssql
import _mssql
import socket
import decimal
import uuid
class MSSQL:
def __init__(self, host, user, pwd, db):
self.host = host
self.user = user
self.pwd = pwd
self.db = db
def __GetConnect(self):
if not self.db:
raise (NameError, "Not Setted")
self.conn = pymssql.connect(host = self.host, user = self.user, password= self.pwd, database=self.db, charset="utf8" )
cur = self.conn.cursor()
if not cur:
raise(NameError, "Connect Error!")
else:
return cur
def ExecQuery(self, sql):
cur = self.__GetConnect()
cur.execute(sql)
resList = cur.fetchall()
self.conn.close()
return resList
def ExecNonQuery(self, sql):
cur = self.__GetConnect()
cur.execute(sql)
self.conn.commit()
self.conn.close()
def main():
ms = MSSQL(host="localhost", user="sa", pwd="prolog.123", db="SyncfloEPM_2.9.0")
resList = ms.ExecQuery("select top 10 ProductID from Products")
for ProductID in resList:
print str(ProductID)
if __name__ == "__main__":
main()