Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
1
Indexable
Never
 encrypt = json_data.get('PPM_PC', {}).get('ENCRYPT')
    host = json_data.get('PPM_PC', {}).get('DB_HOST')
    port = json_data.get('PPM_PC', {}).get('DB_PORT')
    user = json_data.get('PPM_PC', {}).get('DB_USER')
    db_type =json_data.get('PPM_PC', {}).get('DB_TYPE')
    schema = json_data.get(replicationTarget, {}).get('DB_SCHEMA')
    logging.info("DATABASE - HOST FOR PPM_PC - " + host)
    logging.info("DATABASE - PORT FOR PPM_PC - " + port)
    logging.info("DATABASE - USER - PPM_PC" + user)

    if encrypt == 'Y':
        password = base_b64decode(json_data.get('PPM_PC', {}).get('DB_PASSWORD')).decode('utf-8')
    else:
        password = json_data.get('PPM_PC', {}).get('DB_PASSWORD')
    if db_type=='MYSQL':
        cnx = mysql.connector.connect(user=user, password=password, host=host, port=port)
        cursor = cnx.cursor()
        logging.info(f"connected to database server PPM_PC: {host}:{port}")
    elif db_type=='ORACLE':
        import oracledb
        oracle_mode = oracledb.is_thin_mode()
        print("Oracle mode: %s" % oracle_mode)
        if oracle_mode:
            oracledb.init_oracle_client()
            print("Enabled python-oracledb Thick mode")
        else:
            print("Default python-oracledb Thick mode")

        cnx = ('oracle://%s:%s@%s:%s/?service_name=%s' % (user
                                                          , password
                                                          , host
                                                          , port
                                                          , schema
                                                          ))
        connection = sqlalchemy_create_engine(cnx
                                              , encoding="utf8"
                                              )
        connection = connection.raw_connection()
        cursor=connection.cursor()