-
Notifications
You must be signed in to change notification settings - Fork 6
/
mssqlPipe.py
68 lines (52 loc) · 1.42 KB
/
mssqlPipe.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
try:
import logging
import pymssql
except ImportError as e:
print e
logging.error(str(e))
sys.exit(1)
__file__ = 'mssqlPipe'
logger = logging.getLogger(__file__)
# type: mssql
# server: smartitcorp.database.secure.windows.net
# database: iVisa
# username: gb
# password: 7=^{YwjrS!r3mXu.5sOM4wc,MSOzDMZO2EZ"3${342,A2lMytq
class Conn(object):
def __init__(self, srvr, usr, pss, db):
self.srvr = srvr
self.usr = usr
self.pss = pss
self.db = db
pass
# get connection pipe instance
def connect(self):
try:
self.conn = pymssql.connect(server=self.srvr,
user=self.usr, password=self.pss, database=self.db, port=1433)
self.cursor = self.conn.cursor()
except pymssql.Error as e:
print str(e)
logging.error(
'Could not connect to azure database. Reason: {0}'.format(str(e)))
pass
def getConn(self):
return self.conn
def close(self):
self.cursor.close()
self.conn.close()
pass
def executeQuery(self, query):
self.cursor.execute(query)
row = self.cursor.fetchone()
# for i in res:
# print i
return row[0]
def insert(self, query):
pass
def update(self, query):
pass
def delete(self, query):
pass
pass