Ejemplo n.º 1
0
 def init_db(self):
     try:
         self.pool = mysql.connector.pooling.MySQLConnectionPool(
             pool_size=5, **self.dbConfig)
     except NameError:
         ran_num = random.random()
         name_my_pool = 'pool%s' % str(ran_num)
         try:
             self.pool = mariadb.ConnectionPool(
                 pool_size=5,
                 pool_name=name_my_pool,
                 pool_reset_connection=False,
                 host=self.dbConfig['host'],
                 user=self.dbConfig['user'],
                 password=self.dbConfig['password'],
                 database=self.dbConfig['database'])
         except mariadb.ProgrammingError:
             ran_num = random.random()
             name_my_pool = 'pool%s' % str(ran_num)
             self.pool = mariadb.ConnectionPool(
                 pool_size=5,
                 pool_name=name_my_pool,
                 pool_reset_connection=False,
                 host=self.dbConfig['host'],
                 user=self.dbConfig['user'],
                 password=self.dbConfig['password'],
                 database=self.dbConfig['database'])
Ejemplo n.º 2
0
 def test_pool_add(self):
     default_conf = conf()
     pool = mariadb.ConnectionPool(pool_name="test_pool_add")
     try:
         mariadb.ConnectionPool(pool_name="test_pool_add")
     except mariadb.ProgrammingError as e:
         pass
     del pool
Ejemplo n.º 3
0
 def test_pool_add(self):
     default_conf = conf()
     pool = mariadb.ConnectionPool(pool_name="test_pool_add")
     try:
         mariadb.ConnectionPool(pool_name="test_pool_add")
     except mariadb.ProgrammingError as e:
         pass
     pool.close()
     self.assertEqual(mariadb._CONNECTION_POOLS, {})
Ejemplo n.º 4
0
    def test_conpy69(self):
        conn = create_connection()
        cursor1 = conn.cursor()
        cursor1.execute("CREATE SCHEMA IF NOT EXISTS 中文考试")
        default_conf = conf()
        default_conf["database"] = "中文考试"
        pool = mariadb.ConnectionPool(pool_name="test_conpy69")
        try:
            pool.set_config(**default_conf)
        except:
            del pool
            raise

        for i in range(1, 6):
            pool.add_connection()
        conn = mariadb.connect(pool_name="test_conpy69")
        cursor = conn.cursor()
        cursor.execute("select database()")
        row = cursor.fetchone()
        self.assertEqual(row[0], "中文考试")
        cursor.execute(
            "CREATE TABLE t1 (a varchar(255)) character set utf8mb4")
        cursor.execute("insert into t1 values (?)", ("123.45 中文考试", ))
        cursor.execute("select a from t1")
        row = cursor.fetchone()
        self.assertEqual(row[0], "123.45 中文考试")
        cursor1.execute("DROP SCHEMA 中文考试")
        del pool
 def test_pool_add(self):
     default_conf= conf()
     pool= mariadb.ConnectionPool(pool_name="test")
     pool1= mariadb.ConnectionPool(pool_name="test1")
     pool.set_config(**default_conf)
     pool1.set_config(**default_conf)
     conn= create_connection()
     pool.add_connection(conn)
     try:
        pool.add_connection(conn)
     except mariadb.PoolError as e:
        pass
     try:
        pool1.add_connection(conn)
     except mariadb.PoolError as e:
        pass
     del pool, pool1
Ejemplo n.º 6
0
def initConnectionPool():
    global pool
    pool = mariadb.ConnectionPool(user=user,
                                  password=password,
                                  host=host,
                                  port=port,
                                  database=database,
                                  pool_name="app",
                                  pool_size=8)
    return pool
Ejemplo n.º 7
0
 def test__CONNECTION_POOLS(self):
     default_conf = conf()
     pool = mariadb.ConnectionPool(pool_name="test_use", **default_conf)
     conn = mariadb.connect(pool_name="test_use")
     cursor = conn.cursor()
     cursor.execute("SELECT 1")
     row = cursor.fetchone()
     self.assertEqual(row[0], 1)
     del cursor
     del pool
 def test_connection_pool_add(self):
     default_conf= conf()
     pool= mariadb.ConnectionPool(pool_name="test1")
     pool.set_config(**default_conf)
     for i in range(1,6):
         pool.add_connection()
     try:
         pool.add_connection()
     except mariadb.PoolError:
         pass
     del pool
 def test_connection_pool_conf(self):
     pool= mariadb.ConnectionPool(pool_name="test")
     default_conf= conf()
     conn= create_connection()
     try:
         pool.add_connection(conn)
     except mariadb.PoolError:
         pass
     pool.set_config(**default_conf)
     pool.add_connection(conn)
     c= pool.get_connection()
     self.assertEqual(c, conn)
     del pool
Ejemplo n.º 10
0
    def __init__(self, mariadb_config):
        username = mariadb_config['username']
        password = mariadb_config['password']
        host = mariadb_config['host']
        port = int(mariadb_config['port'])
        database = mariadb_config['database']
        pool_name = mariadb_config['connectionpoolname']
        pool_size = int(mariadb_config['connectionpoolsize'])

        print(pool_name)
        try:
            self.pool = mariadb.ConnectionPool(pool_name=pool_name, pool_size=pool_size, username=username, password=password, host=host, port=port, database=database)
        except mariadb.Error as ex:
            raise ex
Ejemplo n.º 11
0
def init_mariadb_datamanger(app: Flask, **config):
    if config is None:
        config = {}

    for suffix in ['HOST', 'USER', 'PASSWORD', 'DB', 'POOL_SIZE']:
        key = f'MARIADB_{suffix}'
        config.setdefault(suffix.lower(), app.config.get(key))

    # print(config)
    mp = mariadb.ConnectionPool(
        **config,
        pool_name="web-app",
    )
    app.mariadb_pool = mp
    app.mariadb = LocalProxy(get_maria_dm)
Ejemplo n.º 12
0
 def test_connection_pool_maxconn(self):
     default_conf = conf()
     pool = mariadb.ConnectionPool(pool_name="test_max_size",
                                   **default_conf)
     connections = []
     for i in range(1, 6):
         connections.append(pool.get_connection())
     try:
         x = pool.get_connection()
     except mariadb.PoolError:
         pass
     for c in connections:
         c.close()
     x = pool.get_connection()
     del pool
    def test_conpy40(self):
        default_conf= conf()
        pool = mariadb.ConnectionPool(pool_name = 'pool1')

        try:
            pool.set_config(pool_size = 3)
        except mariadb.PoolError:
            pass

        pool.set_config(**default_conf)

        for j in range(3):
            c = mariadb.connect(**default_conf)
            pool.add_connection(c)
        del pool
Ejemplo n.º 14
0
def initialize () :
    global DB_CONFIG
    global SERVER_CONFIG
    global UDPServerSocket
    global my_hostname
    global db_pool
    global thread_count_high_water

    try :
        UDPServerSocket = socket.socket (family=socket.AF_INET,
                                        type=socket.SOCK_DGRAM)
        # Bind to address and ip
        UDPServerSocket.bind ((SERVER_CONFIG['LOCAL_IP'],
                                SERVER_CONFIG['LISTENER_PORT']))
        my_hostname = socket.gethostname ()
    except e:
        print(f"Error in UDP socket set up: {e}")
        sys.exit(1)
    print("logger server listening")

    try:
        db_pool = mariadb.ConnectionPool (  # initialize db connection pool
            pool_name='db_pool' ,
            pool_size=DB_CONFIG['POOLSIZE'] ,
            pool_reset_connection = False ,
            host=DB_CONFIG['HOSTNAME'] ,
            port=DB_CONFIG['PORT'] ,
            user=DB_CONFIG['USERNAME'] ,
            passwd=DB_CONFIG['PASSWORD'] ,
            database=DB_CONFIG['DATABASE']
            )
        #except mariadb.Error as e:
        #print(f"Error MariaDB Platform: {e}")
    #except :
        #continue
        thread_count_high_water = DB_CONFIG['POOLSIZE'] - 2
        db_connection = get_db_connection ()
        #---- Set start time, et. al.
        ts_thread = threading.Thread (target=set_initialize_timestamp,
                                        args=(get_db_connection(),))
        ts_thread.start ()
        ts_thread.join ()               # wait for thread to complete
    except mariadb.Error as e:
        print(f"Error MariaDB Platform: {e}")
        sys.exit(1)
    print ('database connection pool initialized')

    allowed_actions ['ping']['handler'] = ping_handler
Ejemplo n.º 15
0
    def test_conpy40(self):
        default_conf = conf()
        pool = mariadb.ConnectionPool(pool_name='test_conpy40')

        try:
            pool.set_config(pool_size=3)
        except mariadb.PoolError:
            pass

        try:
            pool.set_config(**default_conf)
        except:
            pool.close()
            raise

        for j in range(3):
            c = mariadb.connect(**default_conf)
            pool.add_connection(c)
        pool.close()
Ejemplo n.º 16
0
    def test_conpy69(self):
        if is_skysql():
            self.skipTest("skipping on SkySQL")
        if is_maxscale():
            self.skipTest(
                "skipping on Maxscale: bug https://jira.mariadb.org/browse/MXS-3921"
            )
        conn = create_connection()
        conn.autocommit = True
        cursor1 = conn.cursor()
        cursor1.execute(
            "CREATE DATABASE IF NOT EXISTS `中文考试` CHARACTER SET 'utf8mb4'")
        cursor1.execute("COMMIT")
        default_conf = conf()
        default_conf["database"] = "中文考试"
        pool = mariadb.ConnectionPool(pool_name="test_conpy69")
        try:
            pool.set_config(**default_conf)
        except:
            pool.close()
            raise

        try:
            for i in range(1, 6):
                pool.add_connection()
            conn = mariadb.connect(pool_name="test_conpy69")
            conn.autocommit = True
            cursor = conn.cursor()
            cursor.execute("select database()")
            row = cursor.fetchone()
            self.assertEqual(row[0], "中文考试")
            cursor.execute(
                "CREATE TABLE t1 (a varchar(255)) character set utf8mb4")
            cursor.execute("insert into t1 values (?)", ("123.45 中文考试", ))
            cursor.execute("select a from t1", buffered=True)
            row = cursor.fetchone()
            self.assertEqual(row[0], "123.45 中文考试")
            cursor1.execute("DROP SCHEMA 中文考试")
        finally:
            pool.close()
Ejemplo n.º 17
0
 def test_connection_pools(self):
     pool = mariadb.ConnectionPool(pool_name="test_connection")
     self.assertEqual(mariadb._CONNECTION_POOLS["test_connection"], pool)
     del pool
     self.assertEqual(mariadb._CONNECTION_POOLS, {})
Ejemplo n.º 18
0
 def test_conpy39(self):
     try:
         pool = mariadb.ConnectionPool()
     except mariadb.ProgrammingError:
         pass
Ejemplo n.º 19
0
import scad_utils

testing: bool = True
if testing:
    fake_datetime = datetime.datetime(2020, 8, 7, 15, 10)


app = Flask(__name__)
app.config["SECRET_KEY"] = "clave ultra secreta"
app.permanent_session_lifetime = datetime.timedelta(minutes=20)

teacher_time_tolerance = datetime.timedelta(minutes=20)
db = mariadb.ConnectionPool(
    user="******",
    password="******",
    host="localhost",
    pool_name="pul",
    pool_size=20,
    database="scad",
)

# tmp_cursor: mysql.cursor.MySQLCursor = db.cursor()
# tmp_cursor.execute("SET lc_time_names = 'es_PE';")
# tmp_cursor.close()
spanish_days: dict = {
    "Monday": "lunes",
    "Tuesday": "martes",
    "Wednesday": "miércoles",
    "Thursday": "jueves",
    "Friday": "viernes",
    "Saturday": "sábado",
    "Sunday": "domingo",