예제 #1
0
def create_table(query: str):
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(query)
                DB_URL.commit()
                database.close()
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.info(f"An error has occurred while executing CREATE_TABLE: {query_error}")
예제 #2
0
def update_name(tg_id: int, name: str):
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(DB_UPDATE_NAME, (name, tg_id))
                DB_URL.commit()
            return True
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.error(f"An error has occurred while executing DB_UPDATE_NAME query: {query_error}")
            return query_error
예제 #3
0
def unban_user(tg_id: int):
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(DB_UNBAN_USER, (tg_id,))
                DB_URL.commit()
            return True
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.error(f"An error has occurred while executing DB_UNBAN_USER query: {query_error}")
            return query_error
예제 #4
0
def set_user(tg_id: int, tg_uname: str):
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(DB_SET_USER,
                                 (tg_id, tg_uname, time.strftime("%d/%m/%Y %T %p"), 0))
                DB_URL.commit()
            return True
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.error(f"An error has occurred while executing DB_SET_USER query: {query_error}")
            return query_error
예제 #5
0
def get_users():
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(DB_GET_USERS)
                return database.fetchall()
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.error(f"An error has occurred while executing DB_GET_USERS query: {query_error}")
            return query_error
예제 #6
0
def get_user_by_name(tg_uname: str):
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(DB_GET_USER_BY_NAME, (tg_uname,))
                return database.fetchone()
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.error(f"An error has occurred while executing DB_GET_USER_BY_NAME query: {query_error}")
            return query_error
예제 #7
0
def check_banned(tg_id: int):
    try:
        database = DB_URL.cursor()
    except MySQLdb.DatabaseError as connection_error:
        logging.error(f"An error has occurred while connecting to database: {connection_error}")
    else:
        try:
            with database:
                database.execute(DB_CHECK_BANNED, (tg_id,))
                return database.fetchone()
        except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as query_error:
            logging.error(f"An error has occurred while executing DB_CHECK_BANNED query: {query_error}")
            return query_error