-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlServer.py
34 lines (28 loc) · 1 KB
/
SqlServer.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
"""Created on Sept 24, 2015
@author: del20"""
class SqlServer:
def __init__(self, host, port, db, user, password):
self.host = host
self.port = port
self.db = db
self.user = user
self.password = password
self.connection = None
def getConnection(self):
if not self.connection:
import ceODBC
template = 'DRIVER={FreeTDS};Server=%s;Port=%s;Database=%s;UID=%s;PWD=%s;'
conStr = template % (self.host, self.port, self.db, self.user, self.password)
print conStr
self.connection = ceODBC.connect(conStr)
return self.connection
def getFullyQualifyTableName(self, tableName):
tableFullName = tableName
if self.cdm:
tableFullName = self.db + ".dbo." + tableName
return tableFullName
def close(self):
if (self.connection):
self.connection.close()
def escape(self, tableName):
return '[%s]' %(tableName)