Added module for MS SQL access
This commit is contained in:
parent
51fd560f92
commit
7848c972f8
45
fredmssql.py
Executable file
45
fredmssql.py
Executable file
@ -0,0 +1,45 @@
|
||||
import pymssql
|
||||
|
||||
|
||||
class FredDB(object):
|
||||
conn = False
|
||||
cursor = False
|
||||
connected = False
|
||||
|
||||
def __init__(self, user, passwd, dbname):
|
||||
self.user = user
|
||||
self.passwd = passwd
|
||||
self.dbname = dbname
|
||||
self.host = 'NR-CORP-APP1'
|
||||
|
||||
def connect(self):
|
||||
self.conn = pymssql.connect(self.host, self.user,
|
||||
self.passwd, self.dbname)
|
||||
self.connected = True
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
def close(self):
|
||||
if self.cursor:
|
||||
self.cursor.close()
|
||||
self.cursor = False
|
||||
if self.conn:
|
||||
self.conn.close()
|
||||
self.conn = False
|
||||
|
||||
def query(self, sql, data=[]):
|
||||
if not self.conn:
|
||||
self.connect()
|
||||
self.conn.query(sql, data)
|
||||
return self.conn.use_result()
|
||||
|
||||
def execute(self, sql, data=[]):
|
||||
if not self.conn:
|
||||
self.connect()
|
||||
self.cursor.execute(sql, data)
|
||||
return self.cursor.fetchall()
|
||||
|
||||
def executemany(self, sql, data=[]):
|
||||
if not self.conn:
|
||||
self.connect()
|
||||
self.cursor.executemany(sql, data)
|
||||
self.conn.commit()
|
Loading…
Reference in New Issue
Block a user