| 6910 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
|
|
|
3 |
#
|
|
|
4 |
# Module name : jats_rm_query.pl
|
|
|
5 |
# Module type : JATS Utility
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Execute a simple RM SQL query
|
|
|
10 |
#
|
|
|
11 |
# Usage : See POD at the end of this file
|
|
|
12 |
#
|
|
|
13 |
#......................................................................#
|
|
|
14 |
|
|
|
15 |
require 5.008_002;
|
|
|
16 |
use strict;
|
|
|
17 |
use warnings;
|
|
|
18 |
|
|
|
19 |
use Pod::Usage;
|
|
|
20 |
use Getopt::Long;
|
|
|
21 |
|
|
|
22 |
use Pod::Usage;
|
|
|
23 |
use Getopt::Long;
|
|
|
24 |
use JatsError;
|
|
|
25 |
use JatsRmApi;
|
|
|
26 |
use JatsSystem;
|
|
|
27 |
use FileUtils;
|
|
|
28 |
use ConfigurationFile;
|
|
|
29 |
use JatsProperties;
|
|
|
30 |
use File::Copy;
|
|
|
31 |
use DBI;
|
|
|
32 |
my $RM_DB;
|
|
|
33 |
|
|
|
34 |
# ReadOnly credentails to known databases
|
|
|
35 |
my $newRMCred = ['jdbc:oracle:thin:@auawsards002:1521:RELEASEM', 'RM_READONLY', 'Tp8WmmDKMq2Z'];
|
|
|
36 |
my $oldRMCred = ['jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RM_READONLY', 'RM_READONLY'];
|
|
|
37 |
my $rmCred;
|
|
|
38 |
|
|
|
39 |
my $VERSION = 1.0;
|
|
|
40 |
my $opt_help=0;
|
|
|
41 |
my $opt_verbose=0;
|
|
|
42 |
my $opt_debug=0;
|
|
|
43 |
my $opt_pulse;
|
|
|
44 |
my $opt_user;
|
|
|
45 |
my $opt_passwd;
|
|
|
46 |
my $opt_server;
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
#-------------------------------------------------------------------------------
|
|
|
50 |
# Function : Mainline Entry Point
|
|
|
51 |
#
|
|
|
52 |
# Description :
|
|
|
53 |
#
|
|
|
54 |
# Inputs :
|
|
|
55 |
#
|
|
|
56 |
my $result = GetOptions (
|
|
|
57 |
"help:+" => \$opt_help,
|
|
|
58 |
"manual:3" => \$opt_help,
|
|
|
59 |
"verbose:+" => \$opt_verbose,
|
|
|
60 |
"debug:+" => \$opt_debug,
|
|
|
61 |
"pulse!" => \$opt_pulse,
|
|
|
62 |
"user:s" => \$opt_user,
|
|
|
63 |
"password:s" => \$opt_passwd,
|
|
|
64 |
"server:s" => \$opt_server,
|
|
|
65 |
);
|
|
|
66 |
|
|
|
67 |
#
|
|
|
68 |
# UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
|
|
|
69 |
#
|
|
|
70 |
|
|
|
71 |
#
|
|
|
72 |
# Process help and manual options
|
|
|
73 |
#
|
|
|
74 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
75 |
pod2usage(-verbose => 1) if ( $opt_help == 2 );
|
|
|
76 |
pod2usage(-verbose => 2) if ( $opt_help > 2 );
|
|
|
77 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV < 0 );
|
|
|
78 |
|
|
|
79 |
#
|
|
|
80 |
# Configure the error reporting rmMerge_process now that we have the user options
|
|
|
81 |
#
|
|
|
82 |
ErrorConfig( 'name' =>'RMQRY',
|
|
|
83 |
'verbose' => $opt_verbose,
|
|
|
84 |
'debug' => $opt_debug,
|
|
|
85 |
);
|
|
|
86 |
Error('No Query') unless (length($ARGV[0]) > 0);
|
|
|
87 |
|
|
|
88 |
# Configue the Database to use
|
|
|
89 |
$rmCred = $opt_pulse ? $newRMCred : $oldRMCred;
|
|
|
90 |
$rmCred->[0] = $opt_server if defined $opt_server;
|
|
|
91 |
$rmCred->[1] = $opt_user if defined $opt_user;
|
|
|
92 |
$rmCred->[2] = $opt_passwd if defined $opt_passwd;
|
|
|
93 |
|
| 6912 |
dpurdie |
94 |
my ($newData, $colData) = getDataFromRm('Data', $ARGV[0], $rmCred, {dump => $opt_verbose, oneRow => 0, 'error' => 'No data found'});
|
| 6910 |
dpurdie |
95 |
#
|
|
|
96 |
# Determine the max width of every dislpay column (except the last)
|
| 6912 |
dpurdie |
97 |
# Add Column Names as the first row of Data
|
| 6910 |
dpurdie |
98 |
# Process column names and raw data
|
|
|
99 |
#
|
| 6912 |
dpurdie |
100 |
my @colNames;
|
|
|
101 |
foreach my $entry ( @{$colData}) {
|
|
|
102 |
$entry =~ s~^(.*?):~~;
|
|
|
103 |
push @colNames, $1;
|
|
|
104 |
}
|
| 6910 |
dpurdie |
105 |
my @colWidth;
|
| 6912 |
dpurdie |
106 |
my $colNum = ($#$colData) - 1;
|
|
|
107 |
unshift @{$newData}, \@colNames;
|
| 6910 |
dpurdie |
108 |
|
|
|
109 |
foreach my $entry ( @{$newData}) {
|
|
|
110 |
for my $i (0 .. $colNum) {
|
|
|
111 |
if (!defined $entry->[$i] ) {
|
|
|
112 |
$entry->[$i] = ''
|
|
|
113 |
}
|
|
|
114 |
my $len = length($entry->[$i]);
|
|
|
115 |
if ( !defined($colWidth[$i]) || $len > $colWidth[$i]) {
|
|
|
116 |
$colWidth[$i] = $len
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
#
|
|
|
121 |
# Generate a sprintf formatted line
|
|
|
122 |
# With no width arg on the last element
|
|
|
123 |
#
|
|
|
124 |
my $fmtline ='';
|
|
|
125 |
my $fmtJoiner = '';
|
|
|
126 |
foreach (@colWidth) {
|
|
|
127 |
$fmtline .= $fmtJoiner . '%-' . $_ . 's';
|
|
|
128 |
$fmtJoiner = ', ';
|
|
|
129 |
}
|
|
|
130 |
$fmtline .= $fmtJoiner . "%-s\n";
|
|
|
131 |
|
|
|
132 |
#
|
|
|
133 |
# Display the data
|
|
|
134 |
#
|
|
|
135 |
foreach my $entry ( @{$newData}) {
|
|
|
136 |
printf($fmtline, @{$entry});
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
#-------------------------------------------------------------------------------
|
|
|
140 |
# Function : getDataFromRm
|
|
|
141 |
#
|
|
|
142 |
# Description : Get an array of data from RM
|
|
|
143 |
#
|
|
|
144 |
# Inputs : $name - Query Name
|
|
|
145 |
# $m_sqlstr - Query
|
|
|
146 |
# $rmRef - Ref to RM
|
|
|
147 |
# $options - Ref to a hash of options
|
|
|
148 |
# sql - show sql
|
|
|
149 |
# data - show data
|
|
|
150 |
# dump - show results
|
|
|
151 |
# oneRow - Only feth one row
|
|
|
152 |
# error - Must find data
|
|
|
153 |
#
|
|
|
154 |
# Returns : ref to array of data
|
| 6912 |
dpurdie |
155 |
# ref to array of Column Data
|
| 6910 |
dpurdie |
156 |
#
|
|
|
157 |
sub getDataFromRm
|
|
|
158 |
{
|
|
|
159 |
my ($name,$m_sqlstr, $rmRef, $options ) = @_;
|
|
|
160 |
my @row;
|
|
|
161 |
my $data;
|
| 6912 |
dpurdie |
162 |
my $colData;
|
| 6910 |
dpurdie |
163 |
|
|
|
164 |
if (ref $options ne 'HASH') {
|
|
|
165 |
$options = {};
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
$ENV{GBE_RM_LOCATION} = $rmRef->[0];
|
|
|
169 |
$ENV{GBE_RM_USERNAME} = $rmRef->[2];
|
|
|
170 |
$ENV{GBE_RM_PASSWORD} = $rmRef->[1];
|
|
|
171 |
connectRM(\$RM_DB, $opt_verbose);
|
|
|
172 |
|
|
|
173 |
if ($options->{sql}) {
|
|
|
174 |
Message("$name: $m_sqlstr")
|
|
|
175 |
}
|
|
|
176 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
177 |
if ( defined($sth) )
|
|
|
178 |
{
|
|
|
179 |
if ( $sth->execute( ) ) {
|
| 6912 |
dpurdie |
180 |
$colData = $sth->fetch_columndata();
|
| 6910 |
dpurdie |
181 |
if ( $sth->rows ) {
|
|
|
182 |
while ( @row = $sth->fetchrow_array ) {
|
|
|
183 |
if ($options->{data}) {
|
|
|
184 |
Message ("$name: @row");
|
|
|
185 |
}
|
|
|
186 |
#Debug0("$name: @row");
|
|
|
187 |
push @{$data}, [@row];
|
|
|
188 |
|
|
|
189 |
last if $options->{oneRow};
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
$sth->finish();
|
|
|
193 |
} else {
|
|
|
194 |
Error("Execute failure:$name: $m_sqlstr", $sth->errstr() );
|
|
|
195 |
}
|
|
|
196 |
} else {
|
|
|
197 |
Error("Prepare failure:$name" );
|
|
|
198 |
}
|
|
|
199 |
disconnectRM(\$RM_DB);
|
|
|
200 |
|
|
|
201 |
if (!$data && $options->{error}) {
|
|
|
202 |
Error( $options->{error} );
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
if ($data && $options->{oneRow}) {
|
|
|
206 |
$data = $data->[0];
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
if ($options->{dump}) {
|
|
|
210 |
DebugDumpData("$name", $data);
|
|
|
211 |
}
|
| 6912 |
dpurdie |
212 |
return $data, $colData;
|
| 6910 |
dpurdie |
213 |
}
|
|
|
214 |
|
|
|
215 |
#-------------------------------------------------------------------------------
|
|
|
216 |
# Documentation
|
|
|
217 |
#
|
|
|
218 |
|
|
|
219 |
=pod
|
|
|
220 |
|
|
|
221 |
=for htmltoc GENERAL::ClearCase::
|
|
|
222 |
|
|
|
223 |
=head1 NAME
|
|
|
224 |
|
|
|
225 |
rmMerge_listVersions - list versions of a package
|
|
|
226 |
|
|
|
227 |
=head1 SYNOPSIS
|
|
|
228 |
|
|
|
229 |
jats rmMerge_listVersions [options] PackageName PackageVersion -- commands
|
|
|
230 |
|
|
|
231 |
Options:
|
|
|
232 |
-help - brief help message
|
|
|
233 |
-help -help - Detailed help message
|
|
|
234 |
-man - Full documentation
|
|
|
235 |
-verbose[=n] - Enable additional output
|
|
|
236 |
-pulse - Use Pulse Database
|
|
|
237 |
-user=nnn - Specify alternate user name
|
|
|
238 |
-password=nnn - Specify alternate password
|
|
|
239 |
-server=nnn - Specify alternate server string
|
|
|
240 |
|
|
|
241 |
=head1 OPTIONS
|
|
|
242 |
|
|
|
243 |
=over 8
|
|
|
244 |
|
|
|
245 |
=item B<-help>
|
|
|
246 |
|
|
|
247 |
Print a brief help message and exits.
|
|
|
248 |
|
|
|
249 |
=item B<-help -help>
|
|
|
250 |
|
|
|
251 |
Print a detailed help message with an explanation for each option.
|
|
|
252 |
|
|
|
253 |
=item B<-versbose[=n]>
|
|
|
254 |
|
|
|
255 |
Enable additional output
|
|
|
256 |
|
|
|
257 |
=item B<-pulse>
|
|
|
258 |
|
|
|
259 |
This option will case the command to access the Pulse database. The default is to use the standard
|
|
|
260 |
Release Manager database and readonly credentails.
|
|
|
261 |
|
|
|
262 |
=item B<-user=nnn>
|
|
|
263 |
|
|
|
264 |
Specify an alternate user name for the database connection.
|
|
|
265 |
|
|
|
266 |
=item B<-password=nnn>
|
|
|
267 |
|
|
|
268 |
Specify an alternate password for the database connection.
|
|
|
269 |
|
|
|
270 |
=item B<-server=nnn>
|
|
|
271 |
|
|
|
272 |
Specify an alternate server connection string for the database connection.
|
|
|
273 |
|
|
|
274 |
=back
|
|
|
275 |
|
|
|
276 |
=head1 EXAMPLE
|
|
|
277 |
|
|
|
278 |
jats rm_query "select PV_ID,PKG_ID,PKG_VERSION,PKG_LABEL,SRC_PATH from release_manager.package_versions where pv_id=1223354"
|
|
|
279 |
|
|
|
280 |
=cut
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
|
287 |
|