From 7848c972f819172372e652f7f5933d7ba0f44b71 Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Tue, 21 Aug 2018 12:47:02 -0700 Subject: [PATCH] Added module for MS SQL access --- fredmssql.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 fredmssql.py diff --git a/fredmssql.py b/fredmssql.py new file mode 100755 index 0000000..568e357 --- /dev/null +++ b/fredmssql.py @@ -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()