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()