-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOPSPerl_Db.pl
214 lines (168 loc) · 6.16 KB
/
OOPSPerl_Db.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/perl
use DBI
use strict;
my $driver = "mysql";
my $database = "TESTDB";
my $dsn = "DBI:$driver:database=$database";
my $userid = "testuser";
my $password = "test123";
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
my $sth = $dbh->prepare("INSERT INTO TEST_TABLE
(FIRST_NAME, LAST_NAME, GENDER, AGE, INCOME )
values
('john', 'poul', 'M', 30, 13000)");
$sth->execute() or die $DBI::errstr;
$sth->finish();
$dbh->commit or die $DBI::errstr;
$rv = $h->rows;
or
$rv = $DBI::rows
/* */
#!/usr/cti/apps/CSPbase/Perl/bin/perl
# Usage of packages
use strict;
use warnings;
use XML::XPath;
use XML::XPath::XMLParser;
# File Name
my $FILE_NAME="insert_group";
#Database Connection
my $DB_USER="srgkpi";
my $DB_PASS="Kpi~1Mhsp";
my $DB_NAME="RDB1";
my $CONNECT_STRING="$DB_USER\/$DB_PASS\@$DB_NAME";
# Folders
my $BASE_DIR=$ENV{'SRG_SHARE'}."/utils/kpi_seed_values";
my $SEED_XML_FILES_FOLDER="$BASE_DIR/SEED_XML_FILES";
my $SCRIPTS_FOLDER="$BASE_DIR/SCRIPTS";
my $LOG_FOLDER="$BASE_DIR/LOG";
# Shell Script Name
my $EXECUTION_SCRIPT="$SCRIPTS_FOLDER/execute.sh";
# SQL File Name
my $SQL_FILE="$BASE_DIR/$FILE_NAME.sql";
# Log File Name
my $LOG_FILE="$LOG_FOLDER/$FILE_NAME.log";
# XML File Name
my $XML_FILE="$SEED_XML_FILES_FOLDER/$FILE_NAME.xml";
# XSD File Name
my $XSD_FILE="$SEED_XML_FILES_FOLDER/XSD_FILES/$FILE_NAME.xsd";
# XML File Validation
`xmllint --noout --nowarning --schema "$XSD_FILE" "$XML_FILE" 2>&1`;
#`xmlwf $SEED_XML_FILES_FOLDER/$FILE_NAME.xml >>$LOG_FILE`;
my $validate=`cat $XML_FILE | grep "><" | wc -l`;
#Trimming value received from database.
$validate=~ s/^\s+//;
$validate=~ s/\s+$//;
if($validate>0) {
print "\nPlease enter space for null values in the XML file $XML_FILE\n";
exit;
}
# Parser object creation
my $xp = XML::XPath->new(filename => $XML_FILE);
# Declaring all arrays
my (@relay_groups,@group_names);
# Reading XML File
foreach my $node ($xp->find('//insert_group_details/insert_group/relay_group/text()')->get_nodelist) {
if(sprintf(XML::XPath::XMLParser::as_string($node)) eq " ") {
push @relay_groups, sprintf("NULL");
}
else {
push @relay_groups, sprintf(XML::XPath::XMLParser::as_string($node));
}
#print "1: ".XML::XPath::XMLParser::as_string($node)."\n";
}
#print "relay_groups:: @relay_groups \n\n";
foreach my $node ($xp->find('//insert_group_details/insert_group/group_name/text()')->get_nodelist) {
if(sprintf(XML::XPath::XMLParser::as_string($node)) eq " ") {
push @group_names, sprintf("NULL");
}
else {
push @group_names, sprintf(XML::XPath::XMLParser::as_string($node));
}
#print "2: ".XML::XPath::XMLParser::as_string($node)."\n";
}
#print "group_names:: @group_names \n\n";
# Preparing SQL Statement
my $sql="";
my $i=0;
my $group_key=`sqlplus -s $CONNECT_STRING <<-EOF
set head off
select nvl(max(group_key),0) from dim_group\;
exit\;
EOF`;
#Trimming value received from database.
$group_key=~ s/^\s+//;
$group_key=~ s/\s+$//;
#print "group_key=$group_key";
foreach my $var (@group_names) {
$group_key++;
$sql="($group_key,";
if($relay_groups[$i] eq "NULL") {
$sql.="$relay_groups[$i],";
}
else {
$sql.="'$relay_groups[$i]',";
}
if($group_names[$i] eq "NULL") {
$sql.="$group_names[$i])";
}
else {
$sql.="'$group_names[$i]')";
}
#print "SQL Statement [$i] = $sql \n\n";
# Writing SQL Statement to file
`echo "insert into dim_group values$sql\;" >>$SQL_FILE`;
`echo "alter table AGG_GROUP_KPI_COUNTER add partition GRP_$group_key values ($group_key)
(SUBPARTITION P_AGG_GRP_"$group_key"_199901010000
VALUES LESS THAN (to_date('199901010000','yyyymmddhh24mi')));" >>$SQL_FILE`;
`echo "alter table AGG_RELAY_KPI_COUNTER add partition GRP_$group_key values ($group_key)
(SUBPARTITION P_AGG_RELAY_"$group_key"_199901010000
VALUES LESS THAN (to_date('199901010000','yyyymmddhh24mi')));" >>$SQL_FILE`;
`echo "alter table AGG_HOUR_GRP_KPI_COUNTER add partition GRP_$group_key values ($group_key)
(SUBPARTITION P_AGG_HOUR_GRP_"$group_key"_199901010000
VALUES LESS THAN (to_date('199901010000','yyyymmddhh24mi')));" >>$SQL_FILE`;
`echo "alter table AGG_HOUR_RLY_KPI_COUNTER add partition GRP_$group_key values ($group_key)
(SUBPARTITION P_AGG_HOUR_RLY_"$group_key"_199901010000
VALUES LESS THAN (to_date('199901010000','yyyymmddhh24mi')));" >>$SQL_FILE`;
`echo "alter table AGG_DAY_GRP_KPI_COUNTER add partition GRP_$group_key values ($group_key)
(SUBPARTITION P_AGG_DAY_GRP_"$group_key"_199901010000
VALUES LESS THAN (to_date('199901010000','yyyymmddhh24mi')));" >>$SQL_FILE`;
`echo "alter table AGG_DAY_RLY_KPI_COUNTER add partition GRP_$group_key values ($group_key)
(SUBPARTITION P_AGG_DAY_RLY_"$group_key"_199901010000
VALUES LESS THAN (to_date('199901010000','yyyymmddhh24mi')));" >>$SQL_FILE`;
$i++;
}
# Writing SQL Statement to file
`echo "commit\;" >>$SQL_FILE`;
# Executing SQL Statement
print "\n Group Partition and Sub partition creation shall take few hours\n";
`$EXECUTION_SCRIPT $FILE_NAME`;
`rm -rf $SQL_FILE`;
`./KpiSetupSubPartitionsRelay.sh &`;
`./KpiSetupSubPartitionsGroup.sh &`;
print "Complete \n\n";
/* */
Package name : main 1
Package name : Foo 10
Package name : main 100
Package name : main 10
#!/usr/local/bin/perl
use TIME::Local;
$datestring = localtime();
print "Local date and time $datestring\n";
#!/usr/local/bin/perl
$datestring = gmtime();
print "GMT date and time $datestring\n";
/*
Package Export
h2xs -Ax -n Person (ModuleName)
*/
/*
Installing Perl Module
Download a Perl module in the form tar.gz file. Use the following sequence to install any Perl Module Person.pm which has been downloaded in as Person.tar.gz file.
*/
tar xvfz Person.tar.gz
cd Person
perl Makefile.PL
make
make install