#! 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   : Display the currently released version of ALL packages
#                 that are a part of a given release
#
#                 Currently hard coded to Sydney Release-1
#
# Usage:
#
# Version   Who      Date        Description
#
#......................................................................#

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

#use Data::Dumper;
use DBI;
use Cwd;

my $GBE_PERL     = $ENV{'GBE_PERL'};        # Essential ENV variables
my $GBE_CORE     = $ENV{'GBE_CORE'};
my $opt_verbose = 1;
my $RM_DB;
my @GDATA;

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 $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION FROM RELEASE_CONTENT rc, PACKAGE_VERSIONS pv, PACKAGES pkg WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
    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 )
                {
                    my %DATA;
                    $DATA{pv_id}            = $row[0];
                    $DATA{name}             = $row[1];
                    $DATA{version}          = $row[2];
                    push @GDATA, (\%DATA);
print "$row[1], $row[2]\n";                    
                }
            }
            print "--- Finish\n";
            $sth->finish();
        }
    }
    else
    {
        Error("Prepare failure" );
    }
}

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

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


getPkgDetailsByRTAG_ID(2362);           # 2362 : Syd Release 1
#DebugDumpData("GDATA", \@GDATA);
exit;


