Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DBConnection(object):
- def __init__(self, driver, serve,
- database, user, password):
- self.driver = driver
- self.server = server
- self.database = database
- self.user = user
- self.password = password
- def __enter__(self):
- self.dbconn = pyodbc.connect("DRIVER={};".format(self.driver) +
- "SERVER={};".format(self.server) +
- "DATABASE={};".format(self.database) +
- "UID={};".format(self.user) +
- "PWD={};".format(self.password) +
- "CHARSET=UTF8",
- # "",
- ansi=True)
- return self.dbconn
- def __exit__(self, exc_type, exc_val, exc_tb):
- self.dbconn.close()
- def get_database_connection():
- conn = DBConnection.connection
- if not conn:
- conn = DBConnection.connection = DBConnection.create_connection()
- return conn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement