def __init__(self, target=None): super(DatabaseCreator, self).__init__(target) # BaseDatabase class creates self.connection cursor = self.connection.cursor() version = self.mysql_version(cursor) if not version or not self.mysql_version_okay(version): raise MysqlVersionError('MySQL version >= {v} required.'.format( v=MYSQL_VERSION_REQUIRED)) if target and target == "testing": self.db = config.get('database', 'test_db') else: self.db = config.get('database', 'db') self.user = config.get('database', 'user') self.drop_db(cursor) self.create_db(cursor) self.use_db(cursor) self.create_ranges(cursor) self.create_slots(cursor) self.create_trigger_bins_ranges(cursor) self.create_trigger_ains_slots(cursor) self.create_trigger_aupd_slots(cursor) self.create_function_alloc_realloc_slot(cursor) self.create_function_dealloc_slot(cursor) cursor.close()
def __init__(self, *args, **kwargs): user = config.get("database", "user") passwd = config.get("database", "passwd") host = config.get("database", "host") if 'testing' in args: db = config.get("database", "test_db") else: db = config.get("database", "db") self.connection = pymysql.connect( host=host, user=user, passwd=passwd, db=db, cursorclass=pymysql.cursors.DictCursor)
#!/usr/bin/env python3 import pymysql.cursors from config import pconfig as config from db_api import BaseDatabase # forcing a modern version of mysql for the features from exceptions_peri import MysqlVersionError MYSQL_VERSION_REQUIRED = config.get("misc", "mysql_version_required") class DatabaseCreator(BaseDatabase): def __init__(self, target=None): super(DatabaseCreator, self).__init__(target) # BaseDatabase class creates self.connection cursor = self.connection.cursor() version = self.mysql_version(cursor) if not version or not self.mysql_version_okay(version): raise MysqlVersionError('MySQL version >= {v} required.'.format( v=MYSQL_VERSION_REQUIRED)) if target and target == "testing": self.db = config.get('database', 'test_db') else: self.db = config.get('database', 'db') self.user = config.get('database', 'user') self.drop_db(cursor) self.create_db(cursor)