def connect(): if PYOT_RUN_SQLOPERATIONS: import asynctorndb # Try one connection first. conn = asynctorndb.Connect(host = config.sqlHost, user=config.sqlUsername, passwd=config.sqlPassword, database=config.sqlDatabase, no_delay = False, charset='utf8') spawn = config.sqlConnections future = conn.connect() try: yield future except: pass if future.exception(): print("SQL Connection to localhost failed, trying 127.0.0.1") if config.sqlHost == "localhost": config.sqlHost = "127.0.0.1" print("SQL Connection with localhost failed, trying 127.0.0.1") else: spawn -= 1 connections.append(conn) # Make connection pool. for x in range(spawn): conn = asynctorndb.Connect(host = config.sqlHost, user=config.sqlUsername, passwd=config.sqlPassword, database=config.sqlDatabase, no_delay = False, charset='utf8') future = conn.connect() try: yield future except: pass if future.exception(): print("SQL Connection failed", future.exception(), "check SQL settings in config.py!") sys.exit() else: connections.append(conn)
def get(sql): db = asynctorndb.Connect(**MatrixDB_config) yield db.connect() result = yield db.get(sql) yield db.close() raise gen.Return(result)
def execute(sql): db = asynctorndb.Connect(**DB_config) yield db.connect() result = yield db.execute(sql) yield db.close() raise gen.Return(result)