Exemple #1
0
def handler(event, context):
    global logger

    try:
        # Empty list means no keys are required
        args = common.get_parameters(event, [])

        logger = common.initialise_logger(args)

        processes = []

        for query in copy_queries:
            p = multiprocessing.Process(
                target=execute_query_multiple_statements,
                args=(
                    query,
                    args,
                ),
            )
            processes.append(p)
            p.start()

        for process in processes:
            process.join()

        connection = database.get_connection(args)
        database.execute_multiple_statements(drop_query, connection)
        database.execute_statement(rename_query, connection)

        return 200
    except Exception as e:
        logger.error("Failed to execute one or more SQL statement(s)")
        logger.error(e)
        return 500
Exemple #2
0
def handler(event, context):
    global logger

    args = common.get_parameters(event, ["table-name"])

    logger = common.initialise_logger(args)

    # Validate args
    args_valid = True
    if "topic-name" in args and not validate_arg(args["topic-name"]):
        logger.error(
            f"Optional argument 'topic-name' has an invalid value of: {args['topic-name']}"
        )
        args_valid = False

    if not args_valid:
        raise ValueError("Arguments passed to handler failed to validate")

    logger.info("Getting connection to database")
    connection = database.get_connection(args)

    logger.info("Building query")
    query = build_query(args)

    logger.info("Getting connection to database")
    result = database.execute_query_to_dict(query, connection)
    logger.info(f"Query result {result}")

    connection.close()

    return result
 def __init__(self, data_lock, tbr_col_name, analysis_view_col_name, db):
     super(TBRPullingBroker, self).__init__()
     self.data_lock = data_lock
     self.db = db
     self.analysis_col = db[analysis_view_col_name]
     self.metadata_col = db[tbr_col_name]
     self.stop = threading.Event()
     self.broker_name = "TBR Pulling broker"
     _, enc = get_connection(with_enc=True)
     self.encryption_client = enc
def add_user(user_name, user_id, user_pw):
    conn = database.get_connection()

    sql = '''
            insert into user_table (user_name, user_id, user_pw)
            values(%s, %s, %s)
        '''
    cursor = conn.cursor()
    cursor.execute(sql, (user_name, user_id, user_pw))
    conn.commit()
    conn.close()
Exemple #5
0
def handler(event, context):
    global logger

    args = common.get_parameters(event, ["table-name"])

    logger = common.initialise_logger(args)

    connection = database.get_connection(args)

    script_dir = os.path.dirname(__file__)
    rel_path = "../resources"
    abs_file_path = os.path.join(script_dir, rel_path)

    logger.info("Creating table if it does not exist")
    database.execute_statement(
        open(os.path.join(abs_file_path, "create_table.sql")).read().format(
            table_name=common.get_table_name(args)),
        connection,
    )

    logger.info("Creating user if not exists and grant access")
    database.execute_multiple_statements(
        open(os.path.join(abs_file_path, "grant_user.sql")).read().format(
            table_name=common.get_table_name(args)),
        connection,
    )

    logger.info("Create table alteration stored procedures")
    database.execute_multiple_statements(
        open(os.path.join(abs_file_path, "alter_table.sql")).read(),
        connection,
    )

    logger.info("Execute table alteration stored procedures")

    partition_count = args[
        "partition-count"] if "partition-count" in args else 1

    database.call_procedure(
        connection,
        "alter_reconciliation_table",
        [common.get_table_name(args), partition_count],
    )

    logger.info("Validate table and users exist and the structure is correct")
    table_valid = validate_table(args["rds_database_name"],
                                 common.get_table_name(args), connection)

    connection.close()

    if not table_valid:
        raise RuntimeError(
            f"Schema is invalid in table: {common.get_table_name(args)}")
def get_total_board_cnt(board_info_idx):
    conn = database.get_connection()

    sql = '''
            select count(*)
            from board_table
            where board_info_idx = %s
    '''
    cursor = conn.cursor()
    cursor.execute(sql,(board_info_idx))
    result = cursor.fetchone()

    conn.close()
    return result[0]
def get_board_info_name(board_info_idx):
    conn = database.get_connection()

    sql = '''
            select board_info_name
            from board_info_table
            where board_info_idx = %s
        '''

    cusror = conn.cursor()
    cusror.execute(sql, (board_info_idx))
    result = cusror.fetchone()

    conn.close()

    return result[0]
def get_user_login_data(user_id, user_pw):
    conn = database.get_connection()

    sql = '''
            select user_idx, user_name
            from user_table
            where user_id = %s and user_pw = %s
    '''

    cursor = conn.cursor()
    cursor.execute(sql, (user_id, user_pw))
    result = cursor.fetchone()

    conn.close()

    return result
def check_user_id(user_id):
    conn = database.get_connection()

    sql = '''
            select * from user_table
            where user_id = %s
        '''

    cursor = conn.cursor()
    cursor.execute(sql, (user_id))
    result = cursor.fetchone()

    if result == None:
        return True
    else:
        return False
def get_board_content(board_idx):
    conn = database.get_connection()

    sql = '''
            select a1.board_subject, a2.user_name, a1.board_content, a1.board_image, a3.board_info_name
            from board_table a1, user_table a2, board_info_table a3
            where a1.board_writer_idx = a2.user_idx and a1.board_info_idx = a3.board_info_idx and a1.board_idx = %s
        '''

    cursor = conn.cursor()
    print(board_idx)
    cursor.execute(sql,(board_idx))
    result = cursor.fetchone()

    conn.close()

    return result
    def __init__(self, data_lock, queue_col_name, lims_col_name, db):
        self.data_lock = data_lock
        self.broker_name = "LIMS Broker"
        self.find_matcher = {
            "status": ProcessingStatus.WAITING.value,
            "service": "LIMS",
        }
        self.db = db
        self.lims_col = self.db[lims_col_name]
        _, enc = get_connection(with_enc=True)
        self.encryption_client = enc

        super(LIMSRequestBroker, self).__init__(
            self.db,
            self.db[queue_col_name],
            self.broker_name,
            self.find_matcher,
            self.handle_lims_request,
        )
def get_board_list(board_info_idx, page):
    conn = database.get_connection()

    # 현재 페이지의 글 목록의 시작 글의 인덱스
    start_idx = (int(page) -1 ) * 10

    sql = '''
            select a1.board_idx, a1.board_subject, a2.user_name, date_format(a1.board_date, '%%Y-%%m-%%d')
            from board_table a1, user_table a2
            where a1.board_writer_idx = a2.user_idx and a1.board_info_idx = %s
            order by a1.board_idx desc
            limit %s, 10
        '''

    cursor = conn.cursor()
    cursor.execute(sql, (board_info_idx, start_idx))
    result = cursor.fetchall()

    conn.close()

    return result
Exemple #13
0
def handler(event, _):
    global logger

    args = common.get_parameters(
        event,
        [
            "table-name", "reconciler_maximum_age_scale",
            "reconciler_maximum_age_unit"
        ],
    )

    logger = common.initialise_logger(args)

    logger.info("Getting connection to database")
    connection = database.get_connection(args)

    logger.info("Querying for unreconciled records after max age")
    query_unreconciled_after_max_age(connection, args)

    logger.info("Querying for reconciled and unreconciled counts")
    query_reconciled_and_unreconciled_counts(connection, args)

    connection.close()
def add_board_content(board_subject, board_content, board_writer_idx, board_info_idx, board_image) :
    conn = database.get_connection()

    sql = '''
        insert into board_table(board_subject, board_writer_idx, board_date, board_content, board_image, board_info_idx)
        values (%s, %s, sysdate(), %s, %s, %s)
    '''
    
    cursor = conn.cursor()
    cursor.execute(sql, (board_subject, board_writer_idx, board_content, board_image, board_info_idx))
    print(board_subject, board_writer_idx, board_content, board_image, board_info_idx)
    conn.commit()

    # 방금 작성한 글의 번호(글의 번호가 가장 큰 것)을 가져온다.
    sql = '''
            select max(board_idx) from board_table
            where board_info_idx = %s
    '''

    cursor.execute(sql, (board_info_idx))
    result = cursor.fetchone()
    conn.close()

    return result[0]
Exemple #15
0
def execute_query_multiple_statements(query, args):
    query_connection = database.get_connection(args)
    database.execute_multiple_statements(query, query_connection)