def __init__(self, username, password, host='localhost', port=3306, db=None, unix_socket=None): ''' Initialize Sqlite connection. ''' BeeSQLBaseConnection.__init__(self) if not db: raise BeeSQLError('Engine sqlite requires db') try: self.db_connection = sqlite3.connect(db) self.db_connection.row_factory = self.__dict_factory self.cursor = self.db_connection.cursor() except sqlite3.OperationalError, oe: raise BeeSQLDatabaseError(str(oe))
def __init__(self, username, password, host='localhost', port=3306, db=None, unix_socket=None): ''' Initialize MysqlConnection. Initialize BaseConnection, register database connection and cursor. If db is specified issue a use query. ''' BeeSQLBaseConnection.__init__(self) if (not username or password is None): raise BeeSQLError('Engine mysql requires username and password') try: if not unix_socket: self.db_connection = pymysql.connect(user=username, passwd=password, host=host, port=port) else: self.db_connection = pymysql.connect(user=username, passwd=password, unix_socket=unix_socket) self.cursor = self.db_connection.cursor(pymysql.cursors.DictCursor) if db and db != '': self.cursor.execute('use %s' % (db)) except pymysql.err.DatabaseError, de: raise BeeSQLDatabaseError(str(de))