########################################################################
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
#
# Module name   : jats_rm_play24.pl
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s): jats
#
# Description   : Test if a package is in subversion
#
#
#......................................................................#

require 5.006_001;
use strict;
use warnings;
use JatsError;
use JatsSystem;
use Getopt::Long;
use Pod::Usage;                             # required for help support
use JatsRmApi;

use DBI;

my $VERSION = "1.2.3";                      # Update this
my $opt_verbose = 1;
my $opt_help = 0;
my $opt_manual;
my $RM_DB;
my $DM_DB;

#-------------------------------------------------------------------------------
# Function        : Main Entry
#
# Description     :
#
# Inputs          :
#
# Returns         :
#
my $result = GetOptions (
                "help+"         => \$opt_help,          # flag, multiple use allowed
                "manual"        => \$opt_manual,        # flag
                "verbose+"      => \$opt_verbose,       # flag
                );

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
pod2usage(-verbose => 1)  if ($opt_help == 2 );
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));


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

getInSubversion( 210 );

sub getInSubversion
{
    my ($pkg_id ) = @_;
    my $found = 0;
    my @rows;

    connectRM(\$RM_DB) unless $RM_DB;
    #
    #   Now extract the package dependacies
    #
    my $m_sqlstr = "SELECT COUNT(*)".
                  " FROM  ".
                  "         RELEASE_MANAGER.PACKAGE_VERSIONS pv ".
                  " WHERE ".
                  "         pv.PKG_ID = $pkg_id" .
                  "         AND pv.VCS_TYPE_ID = 24" .
                  "";
$m_sqlstr =~ s~\s+~ ~g;
print "\n\n$m_sqlstr\n";
    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            if ( $sth->rows )
            {
                while ( my @row = $sth->fetchrow_array )
                {
                    print "-- @row\n";
                    $found = 1;
                }
            }
            $sth->finish();
        }
        else
        {
            Error("GetDepends:Execute failure: $m_sqlstr", $sth->errstr() );
        }
    }
    else
    {
        Error("GetDepends:Prepare failure" );
    }

    unless ( $found )
    {
        Warning("No Package Version data for: $pkg_id");
    }
}

