Rtmgr/Gen/Db.pm

filter: Statementstmt 10.8% 26 / 240 Branchbran 0.0% 0 / 114 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.0% 8 / 17 Podpod 0.0% 0 / 8 totaltotal 8.9% 34 / 379 CC 60 SCAR 46.1
CC
60
Cov
7%
get_name
210.0
get_tracker
210.0
calc_scene
72.0
CRAP 100.5
↑ Summary Rtmgr.pm »
1 package Rtmgr::Gen::Db;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use diagnostics;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XML::RPC;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 our @EXPORT_OK = qw(get_download_list create_db_table get_name get_tracker calc_scene insert_into_database_missing get_difference_between_server_and_database add_remove_extraneous_reccords);
13
14 =head1 NAME
15  
16 Rtmgr::Gen::Db - Connect to rTorrent/ruTorrent installation and get a list of torrents, storing them to a database.
17  
18 =head1 VERSION
19  
20 Version 0.05
21  
22 =cut
23  
24 1 our $VERSION = '0.05';
25  
26  
27 =head1 SYNOPSIS
28  
29 Connects to a rTorrent/ruTorrent installation.
30  
31 This module connects to an installation of rTorrent/ruTorrent and builds a local SQLite database with the content of the seedbox.
32  
33 =head1 SUBROUTINES/METHODS
34  
35 #!/usr/bin/env perl
36 use Data::Dump qw(dump);
37  
38 use Rtmgr::Gen qw(get_download_list create_db_table get_name get_tracker calc_scene insert_into_database_missing get_difference_between_server_and_database add_remove_extr$
39 # Create Database.
40 my $create_db = create_db_table('database');
41 print $create_db;
42  
43 # Populate database with ID's 'HASH' of torrents.
44 my $dl_list_arr_ref = get_download_list('user','password','host','443','RPC2','database');
45 insert_into_database_missing($dl_list_arr_ref,'database');
46  
47 # Remove Extraneous Reccords from Database.
48 my $dl_list_ext_reccords = get_download_list('user','password','host','443','RPC2','database');
49 my $diff_list = get_difference_between_server_and_database($dl_list_ext_reccords,'database');
50 add_remove_extraneous_reccords($diff_list,'database');
51  
52 # Populate database with Torrent Names.
53 my $get_name = get_name('user','password','host','443','RPC2','database');
54 print $get_name;
55  
56 # Populate database with trackers.
57 my $get_tracker = get_tracker('user','password','host','443','RPC2','database');
58 print $get_tracker;
59  
60 # Check if release is a scene release by checking for entry in srrdb.
61 my $calc_scene = calc_scene('user','password','database');
62 print $calc_scene;
63  
64 =head2 get
65  
66 =cut
67 0 ▶sub create_db_table {
Subroutine create_db_table: not called CC=4 SCAR=30.0
Pod undocumented
68 0 my ($s_file) = @_;
69  
70 # Check to see if file exists or not. If not create it.
71 0 ▶ if (-e "$s_file".".db") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$s_file" . '.db') { } 0 0 0
72 0 print "\nDatabase exists.\n";
73 } else {
74 0 print "\nCreating Database...\n";
75 # Open SQLite database.
76 0 my $driver = "SQLite";
77 0 my $database = "$s_file.db";
78 0 my $dsn = "DBI:$driver:dbname=$database";
79 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
80 0 my $password = ""; # Not implemented.
81 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
82  
83 0 print "Opened database successfully\n";
84  
85 # Create the database tables.
86 0 my $stmt = qq(CREATE TABLE SEEDBOX
87 (ID TEXT PRIMARY KEY NOT NULL,
88 BLANK TEXT NOT NULL,
89 SCENE TEXT NOT NULL,
90 TRACKER TEXT NOT NULL,
91 NAME TEXT NOT NULL););
92 # Error checking.
93 0 my $rv = $dbh->do($stmt);
94 0 ▶ if($rv < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) { } 0 0 0
95 0 print $DBI::errstr;
96 } else {
97 0 print "Table created successfully\n";
98 }
99 0 $dbh->disconnect();
100 }
101 }
102  
103 0 ▶sub get_download_list {
Subroutine get_download_list: not called CC=7 SCAR=40.3
Pod undocumented
104 0 my ($s_user, $s_pw, $s_url, $s_port, $s_endp, $s_file) = @_;
105 ## Validate input from ARGV
106 0 ▶ if (not defined $s_user) { die "USEAGE: Missing server user.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_user) 0 0 0
107 0 ▶ if (not defined $s_pw) { die "USEAGE: Missing server password.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_pw) 0 0 0
108 0 ▶ if (not defined $s_url) { die "USEAGE: Missing server url.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_url) 0 0 0
109 0 ▶ if (not defined $s_port) { die "USEAGE: Missing server port.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_port) 0 0 0
110 0 ▶ if (not defined $s_endp) { die "USEAGE: Missing server endpoint.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_endp) 0 0 0
111 0 ▶ if (not defined $s_file) { die "USEAGE: Missing server db-filename.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_file) 0 0 0
112 # Run Example: perl gen-db.pl user pass host port endpoint
113 0 my $xmlrpc = XML::RPC->new("https://$s_user\:$s_pw\@$s_url\:$s_port\/$s_endp");
114  
115 0 return $xmlrpc->call( 'download_list' );
116 }
117  
118 0 ▶sub insert_into_database_missing {
Subroutine insert_into_database_missing: not called CC=5 SCAR=34.0
Pod undocumented
119 0 foreach my $i (@{ $_[0] }){
120 0 my $hash_search = _lookup_hash($_[1],$i);
121 0 ▶ if ($hash_search == '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_search == '0') { } 0 0 0
122 0 print "HASH: NOT IN DATABSE ... Adding ...\n";
123 # Open SQLite database.
124 0 my $driver = "SQLite";
125 0 my $database = "$_[1].db";
126 0 my $dsn = "DBI:$driver:dbname=$database";
127 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
128 0 my $password = ""; # Not implemented.
129 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
130 # Insert the value into the database.
131 0 my $stmt = qq(INSERT INTO SEEDBOX (ID,BLANK,SCENE,TRACKER,NAME)
132 VALUES ('$i', '', '', '', ''));
133 0 ▶ my $rv = $dbh->do($stmt) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $dbh->do($stmt) or die $DBI::errstr 0 0 0
134 0 $dbh->disconnect();
135 } else {
136 0 print "HASH: $i \n";
137 }
138 }
139 }
140  
141 0 ▶sub get_difference_between_server_and_database {
Subroutine get_difference_between_server_and_database: not called CC=5 SCAR=34.0
Pod undocumented
142 # $_[0]; # Reference to download list hash. Dereference with @{ $_[0] }
143 # $_[1]; # Scalar of name of database file.
144  
145 # Open SQLite database.
146 0 my $driver = "SQLite";
147 0 my $database = "$_[1].db";
148 0 my $dsn = "DBI:$driver:dbname=$database";
149 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
150 0 my $password = ""; # Not implemented.
151 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
152  
153 0 my $stmt = qq(SELECT ID from SEEDBOX;);
154 0 my $sth = $dbh->prepare( $stmt );
155 0 ▶ my $rv = $sth->execute() or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $sth->execute or die $DBI::errstr 0 0 0
156
157 0 my @disk_array;
158 # Go through every item in database in while loop.
159 0 ▶ while(my @row = $sth->fetchrow_array()){
Branch: 1 branch
BranchTrueFalseTotal
if (my(@row) = $sth->fetchrow_array) 0 0 0
160 0 push(@disk_array, $row[0])
161 }
162 0 ▶ if( $rv < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) 0 0 0
163 0 print $DBI::errstr;
164 }
165 # Check if there is a difference between the two arrays.
166 0 my %diff1;
167 my %diff2;
168  
169 0 @diff1{ @disk_array } = @disk_array;
170 0 delete @diff1{ @{ $_[0] } };
171 # %diff1 contains elements from '@disk_array' that are not in '@{ $_[0] }'
172  
173 0 @diff2{ @{ $_[0] } } = @{ $_[0] };
174 0 delete @diff2{ @disk_array };
175 # %diff2 contains elements from '@{ $_[0] }' that are not in '@disk_array'
176  
177 0 my @k = (keys %diff1, keys %diff2);
178  
179 0 return(\@k);
180  
181 0 $dbh->disconnect();
182 }
183  
184 0 ▶sub add_remove_extraneous_reccords{
Subroutine add_remove_extraneous_reccords: not called CC=6 SCAR=37.4
Pod undocumented
185 # Open SQLite database.
186 0 my $driver = "SQLite";
187 0 my $database = "$_[1].db";
188 0 my $dsn = "DBI:$driver:dbname=$database";
189 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
190 0 my $password = ""; # Not implemented.
191 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
192  
193  
194 0 print "\nExtraneous Database Reccords: \n";
195 # $_[0] is an array reference to either add or delete from database.
196 0 foreach my $i (@{ $_[0] }){
197 0 print "Key: $i\n";
198  
199 0 my $hash_search = _lookup_hash($_[1],$i);
200 0 ▶ if ($hash_search == '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_search == '0') { } 0 0 0
201 0 print "HASH: $i \n\t NOT IN DATABSE ... Adding ...\n";
202 0 my $stmt = qq(INSERT INTO SEEDBOX (ID,BLANK,SCENE,TRACKER,NAME)
203 VALUES ('$i', '', '', '', ''));
204 0 ▶ my $rv = $dbh->do($stmt) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $dbh->do($stmt) or die $DBI::errstr 0 0 0
205 } else {
206 0 print "Key: $i | Does not belong in database.\n";
207 # Delete Operation.
208 0 my $stmt = qq(DELETE from SEEDBOX where ID = $i;);
209 0 ▶ my $rv = $dbh->do($stmt) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $dbh->do($stmt) or die $DBI::errstr 0 0 0
210 }
211 }
212 0 $dbh->disconnect();
213 }
214  
215 0 ▶sub _lookup_hash {
Subroutine _lookup_hash: not called CC=5 SCAR=34.0
216 # This sub is passed the filename of a database, and a hash.
217 # If the hash exists in the database it returns the hash.
218 # If the hash does not exist in the database returns a 0.
219 0 my ($s_file, $hash) = @_;
220  
221 # Open SQLite database.
222 0 my $driver = "SQLite";
223 0 my $database = "$s_file.db";
224 0 my $dsn = "DBI:$driver:dbname=$database";
225 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
226 0 my $password = ""; # Not implemented.
227 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
228  
229 # Run a check to see if the hash already exists in database.
230 0 my $stmt = qq(SELECT ID FROM SEEDBOX WHERE ID = "$hash";);
231 0 my $sth = $dbh->prepare( $stmt );
232 0 ▶ my $rv = $sth->execute() or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $sth->execute or die $DBI::errstr 0 0 0
233  
234 0 my @row = $sth->fetchrow_array();
235  
236 0 ▶ if( $rv < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) { } 0 0 0
237 0 print $DBI::errstr;
238 } else {
239 # Check if the $row[0] returned from the database query has a value or not.
240 0 ▶ if(exists($row[0])){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $row[0]) { } 0 0 0
241 } else {
242 0 return('0');
243 }
244 }
245 # Disconnect from database.
246 0 $sth->finish();
247 0 $dbh->disconnect();
248 }
249  
250 0 ▶sub get_name {
Subroutine get_name: not called CC=14 SCAR=53.5
Pod undocumented
251 0 my ($s_user, $s_pw, $s_url, $s_port, $s_endp, $s_file) = @_;
252  
253 ## Validate input from ARGV
254 0 ▶ if (not defined $s_user) { die "USEAGE: Missing server user.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_user) 0 0 0
255 0 ▶ if (not defined $s_pw) { die "USEAGE: Missing server password.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_pw) 0 0 0
256 0 ▶ if (not defined $s_url) { die "USEAGE: Missing server url.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_url) 0 0 0
257 0 ▶ if (not defined $s_port) { die "USEAGE: Missing server port.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_port) 0 0 0
258 0 ▶ if (not defined $s_endp) { die "USEAGE: Missing server endpoint.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_endp) 0 0 0
259 0 ▶ if (not defined $s_file) { die "USEAGE: Missing server db-filename.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_file) 0 0 0
260 # Run Example: perl gen-db.pl user pass host port endpoint
261 0 my $xmlrpc = XML::RPC->new("https://$s_user\:$s_pw\@$s_url\:$s_port\/$s_endp");
262  
263 # Open SQLite database.
264 0 my $driver = "SQLite";
265 0 my $database = "$s_file.db";
266 0 my $dsn = "DBI:$driver:dbname=$database";
267 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
268 0 my $password = ""; # Not implemented.
269 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
270  
271 0 print "Opened database successfully\n";
272  
273 # Open database and itterate through it.
274 0 my $stmt = qq(SELECT ID, BLANK, SCENE, TRACKER, NAME from SEEDBOX;);
275 0 my $sth = $dbh->prepare( $stmt );
276 0 ▶ my $rv = $sth->execute() or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $sth->execute or die $DBI::errstr 0 0 0
277  
278 0 ▶ if($rv < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) 0 0 0
279 0 print $DBI::errstr;
280 }
281  
282 0 ▶ while(my @row = $sth->fetchrow_array()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@row) = $sth->fetchrow_array) 0 0 0
283 # Look in $row[4] for a value. if it is empty fetch a name for the hash in $row[0].
284 0 ▶ if($row[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row[4]) { } 0 0 0
285 0 print "NAME: $row[4]\n";
286 } else {
287 # Send a call to rtorrent and get the name of the corrisponding hash.
288 0 my $name = $xmlrpc->call( 'd.get_name',"$row[0]" );
289 # Update the corrisponding reccord in the database.
290 0 my $stmt = qq(UPDATE SEEDBOX set NAME = "$name" where ID='$row[0]';);
291 0 ▶ my $rv = $dbh->do($stmt) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $dbh->do($stmt) or die $DBI::errstr 0 0 0
292  
293 0 ▶ if( $rv < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) { } 0 0 0
294 0 print $DBI::errstr;
295 } else {
296 0 print "ADDED: $name\n";
297 }
298 }
299 }
300 0 print "Operation done successfully\n";
301 # Disconnect from database.
302 0 $dbh->disconnect();
303 }
304  
305 0 ▶sub get_tracker {
Subroutine get_tracker: not called CC=14 SCAR=53.5
Pod undocumented
306 0 my ($s_user, $s_pw, $s_url, $s_port, $s_endp, $s_file) = @_;
307  
308 ## Validate input from ARGV
309 0 ▶ if (not defined $s_user) { die "USEAGE: Missing server user.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_user) 0 0 0
310 0 ▶ if (not defined $s_pw) { die "USEAGE: Missing server password.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_pw) 0 0 0
311 0 ▶ if (not defined $s_url) { die "USEAGE: Missing server url.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_url) 0 0 0
312 0 ▶ if (not defined $s_port) { die "USEAGE: Missing server port.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_port) 0 0 0
313 0 ▶ if (not defined $s_endp) { die "USEAGE: Missing server endpoint.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_endp) 0 0 0
314 0 ▶ if (not defined $s_file) { die "USEAGE: Missing server db-filename.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s_file) 0 0 0
315 # Run Example: perl gen-db.pl user pass host port endpoint
316 0 my $xmlrpc = XML::RPC->new("https://$s_user\:$s_pw\@$s_url\:$s_port\/$s_endp");
317 # my $dl_list = $xmlrpc->call( 'download_list' );
318  
319 # Open SQLite database.
320 0 my $driver = "SQLite";
321 0 my $database = "$s_file.db";
322 0 my $dsn = "DBI:$driver:dbname=$database";
323 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
324 0 my $password = ""; # Not implemented.
325 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
326  
327 0 print "Opened database successfully\n";
328
329 # Open database and itterate through it.
330 0 my $stmt = qq(SELECT ID, BLANK, SCENE, TRACKER, NAME from SEEDBOX;);
331 0 my $sth = $dbh->prepare( $stmt );
332 0 ▶ my $rv = $sth->execute() or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $sth->execute or die $DBI::errstr 0 0 0
333  
334 0 ▶ if($rv < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) 0 0 0
335 0 print $DBI::errstr;
336 }
337 0 ▶ while(my @row = $sth->fetchrow_array()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@row) = $sth->fetchrow_array) 0 0 0
338 # Check to see if the NAME value is populated.
339 0 ▶ if($row[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row[3]) { } 0 0 0
340 0 print "HASH: ".$row[0]."\tBLANK: ".$row[1]."\tSCENE: ".$row[2]."\n\tTRACKER: ".$row[3]."\n\tNAME: ".$row[4]."\n";
341 } else {
342 # Get name for specific reccord in the loop.
343 0 my $url = $xmlrpc->call( 't.url',"$row[0]:t0" );
344 #dump($url); # Dump the call for testing purposes.
345 # Update reccords.
346 0 my $stmt = qq(UPDATE SEEDBOX set TRACKER = "$url" where ID='$row[0]';);
347 0 ▶ my $rv = $dbh->do($stmt) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $dbh->do($stmt) or die $DBI::errstr 0 0 0
348  
349 0 ▶ if( $rv < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) { } 0 0 0
350 0 print $DBI::errstr;
351 } else {
352 0 print "HASH: ".$row[0]."\tBLANK: ".$row[1]."\tSCENE: ".$row[2]."\n\tTRACKER: ".$url."\n\tNAME: ".$row[4]."\n";
353 }
354 }
355 }
356 0 print "Operation done successfully\n";
357 # Disconnect from database.
358 0 $dbh->disconnect();
359 }
360  
361 0 ▶sub calc_scene {
Subroutine calc_scene: not called CC=8 SCAR=42.8
Pod undocumented
362 0 my ($s_usr, $s_pw, $s_file) = @_;
363  
364 0 print "Active Database: $s_file\n";
365  
366 # Open SQLite database.
367 0 my $driver = "SQLite";
368 0 my $database = "$s_file.db";
369 0 my $dsn = "DBI:$driver:dbname=$database";
370 0 my $userid = ""; # Not implemented no need for database security on local filesystem at this time.
371 0 my $password = ""; # Not implemented.
372 0 ▶ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect($dsn, $userid, $password, {"RaiseError", 1}) or die $DBI::errstr 0 0 0
373  
374 0 print "Opened database successfully\n";
375
376 # Open database and itterate through it.
377 0 my $stmt = qq(SELECT ID, BLANK, SCENE, TRACKER, NAME from SEEDBOX;);
378 0 my $sth = $dbh->prepare( $stmt );
379 0 ▶ my $rv = $sth->execute() or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $sth->execute or die $DBI::errstr 0 0 0
380  
381 0 ▶ if($rv < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) 0 0 0
382 0 print $DBI::errstr;
383 }
384  
385 0 ▶ while(my @row = $sth->fetchrow_array()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@row) = $sth->fetchrow_array) 0 0 0
386 # Check to see if the NAME value is populated.
387 0 print "\nID: $row[0]\t";
388  
389 0 ▶ if($row[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row[2]) { } 0 0 0
390 0 print "\tsrrDB: $row[2]\n";
391 0 print "\tTRACKER: $row[3]\n";
392 0 print "\tNAME: $row[4]\n";
393 } else {
394 0 print "\n\t * * * Searching * * * $row[4]\n";
395 0 my $srrdb_query = qx(srrdb --username=$s_usr --password=$s_pw -s "$row[4]");
396  
397 # Create Database Reccord.
398 0 my $stmt = qq(UPDATE SEEDBOX set SCENE = "$srrdb_query" where ID='$row[0]';);
399 0 ▶ my $rv = $dbh->do($stmt) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $dbh->do($stmt) or die $DBI::errstr 0 0 0
400 0 ▶ if( $rv < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) { } 0 0 0
401 0 print $DBI::errstr;
402 } else {
403 0 print "\tsrrDB: $srrdb_query\n";
404 0 print "\tTRACKER: $row[3]\n";
405 0 print "\tNAME: $row[4].\n";
406 }
407 }
408  
409 0 print "\t---\n";
410 }
411 0 print "\nOperation done successfully\n";
412  
413 # Disconnect from database.
414 0 $dbh->disconnect();
415 }
416  
417 =head1 AUTHOR
418  
419 Clem Morton, C<< <clem at cpan.org> >>
420  
421 =head1 BUGS
422  
423 Please report any bugs or feature requests to C<bug-rtmgr-gen-db at rt.cpan.org>, or through
424 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rtmgr-Gen-Db>. I will be notified, and then you'll
425 automatically be notified of progress on your bug as I make changes.
426  
427 =head1 SUPPORT
428  
429 You can find documentation for this module with the perldoc command.
430  
431 perldoc Rtmgr::Gen::Db
432  
433 You can also look for information at:
434  
435 =over 4
436  
437 =item * RT: CPAN's request tracker (report bugs here)
438  
439 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Rtmgr-Gen-Db>
440  
441 =item * AnnoCPAN: Annotated CPAN documentation
442  
443 L<http://annocpan.org/dist/Rtmgr-Gen-Db>
444  
445 =item * CPAN Ratings
446  
447 L<https://cpanratings.perl.org/d/Rtmgr-Gen-Db>
448  
449 =item * Search CPAN
450  
451 L<https://metacpan.org/release/Rtmgr-Gen-Db>
452  
453 =back
454  
455  
456 =head1 ACKNOWLEDGEMENTS
457  
458  
459 =head1 LICENSE AND COPYRIGHT
460  
461 This software is Copyright (c) 2020 by Clem Morton.
462  
463 This is free software, licensed under:
464  
465 The Artistic License 2.0 (GPL Compatible)
466  
467 =cut
468  
469 1 1; # End of Rtmgr::Gen::Db
↑ Summary Rtmgr.pm »