#! perl
########################################################################
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
#
# Module name   : jats.sh
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s): jats
#
# Description   : Deployment Manager play script
#
#
# Usage:
#
# Version   Who      Date        Description
#
#......................................................................#

require 5.006_001;
use strict;
use warnings;
use JatsError;
use DBI;
use JatsRmApi;

#use Data::Dumper;
use Cwd;
my $opt_verbose = 1;
my $RM_DB;

sub getPkgDetailsByRTAG_ID
{
    my ($RTAG_ID) =@_;
    my $foundDetails = 0;
    my (@row);

    # if we are not or cannot connect then return 0 as we have not found anything
    connectRM( \$RM_DB );

    # First get details from pv_id

#    my $bom_id = 10083;
#    my $node_id = 26718;
#    my $os_id = 27318;

my    $bom_id = 13543;
my    $os_id = 39544;

    my $m_sqlstr = "SELECT osc.*, pkg.pkg_name, pv.pkg_version, pd.IS_REJECTED, pv.IS_PATCH,pv.IS_OBSOLETE, pkg.pkg_id" .
                " FROM PACKAGES pkg, PACKAGE_VERSIONS pv,PRODUCT_DETAILS pd,".
	            "(" .
#		        " SELECT osc.seq_num, osc.prod_id, osc.product_comments, osc.change_log_flag, osc.is_node_spec".
		        " SELECT osc.seq_num, osc.prod_id".
		        " FROM os_contents osc".
		        " WHERE osc.os_id = $os_id" .
	            " ) osc" .
                " WHERE pd.PROD_ID (+)= pv.PV_ID" .
                "   AND pv.pkg_id = pkg.pkg_id" .
                "   AND osc.PROD_ID = pv.pv_id" .
#                "   AND pv.IS_PATCH =''" .
                " ORDER BY osc.SEQ_NUM desc" ;

    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            print "--- Execute\n";
            if ( $sth->rows )
            {
                print "--- Execute ROWS\n";
                while ( @row = $sth->fetchrow_array )
                {
print "---- ".join (',',@row)."\n";
#                    my $idx = 0;
#                    foreach my $el ( @row )
#                    {
#                        $idx++;
#                        print "$idx :: $el\n";
#                    }
                }
            }
            print "--- Finish\n";
            $sth->finish();
        }
    }
    else
    {
        Error("Prepare failure" );
    }
}

#-------------------------------------------------------------------------------
# Function        : Main
#
# Description     :
#
# Inputs          :
#
# Returns         :
#

ErrorConfig( 'name'    =>'DM_PLAY01' );

getPkgDetailsByRTAG_ID(1861);               # Sydney Legacy
exit;



