Lines 19-25
my $GLOBAL = {
Link Here
|
19 |
}; |
19 |
}; |
20 |
|
20 |
|
21 |
my $OPTIONS = { |
21 |
my $OPTIONS = { |
22 |
criteria => [] |
22 |
where => [] |
23 |
, flags => { |
23 |
, flags => { |
24 |
verbose => '' |
24 |
verbose => '' |
25 |
, commit => '' |
25 |
, commit => '' |
Lines 30-36
my $OPTIONS = {
Link Here
|
30 |
}; |
30 |
}; |
31 |
|
31 |
|
32 |
GetOptions( |
32 |
GetOptions( |
33 |
'criteria=s' => $OPTIONS->{criteria} |
33 |
'where=s' => $OPTIONS->{where} |
34 |
, 'v|verbose' => sub { $OPTIONS->{flags}->{verbose} = 1 } |
34 |
, 'v|verbose' => sub { $OPTIONS->{flags}->{verbose} = 1 } |
35 |
, 'V|version' => sub { $OPTIONS->{flags}->{version} = 1 } |
35 |
, 'V|version' => sub { $OPTIONS->{flags}->{version} = 1 } |
36 |
, 'h|help' => sub { $OPTIONS->{flags}->{help} = 1 } |
36 |
, 'h|help' => sub { $OPTIONS->{flags}->{help} = 1 } |
Lines 38-54
GetOptions(
Link Here
|
38 |
, 'c|commit' => sub { $OPTIONS->{flags}->{commit} = 1 } # aka DO-EET! |
38 |
, 'c|commit' => sub { $OPTIONS->{flags}->{commit} = 1 } # aka DO-EET! |
39 |
); |
39 |
); |
40 |
|
40 |
|
41 |
my @criteria = @{ $OPTIONS->{criteria} }; |
41 |
my @where = @{ $OPTIONS->{where} }; |
42 |
|
42 |
|
43 |
pod2usage( -verbose => 2 ) if $OPTIONS->{flags}->{manual}; |
43 |
pod2usage( -verbose => 2 ) if $OPTIONS->{flags}->{manual}; |
44 |
pod2usage( -verbose => 1 ) if $OPTIONS->{flags}->{help}; |
44 |
pod2usage( -verbose => 1 ) if $OPTIONS->{flags}->{help}; |
45 |
pod2usage( -verbose => 1 -msg => 'You must supply at least one --criteria option' ) if scalar @criteria == 0; |
45 |
pod2usage( -verbose => 1 -msg => 'You must supply at least one --where option' ) if scalar @where == 0; |
46 |
|
46 |
|
47 |
sub verbose { |
47 |
sub verbose { |
48 |
say @_ if $OPTIONS->{flags}->{verbose}; |
48 |
say @_ if $OPTIONS->{flags}->{verbose}; |
49 |
} |
49 |
} |
50 |
|
50 |
|
51 |
my $where_clause = ' where ' . join ( " and ", @criteria ); |
51 |
my $where_clause = ' where ' . join ( " and ", @where ); |
52 |
|
52 |
|
53 |
verbose "Where statement: $where_clause"; |
53 |
verbose "Where statement: $where_clause"; |
54 |
|
54 |
|
Lines 74-80
delete_items.pl - A batch item deletion tool, which generates a query against th
Link Here
|
74 |
|
74 |
|
75 |
delete_items.pl [--help|--manual] |
75 |
delete_items.pl [--help|--manual] |
76 |
|
76 |
|
77 |
delete_items.pl [--verbose] --criteria "I<SQL CONDITIONAL EXPRESSION>" ... [--commit] |
77 |
delete_items.pl [--verbose] --where "I<SQL CONDITIONAL EXPRESSION>" ... [--commit] |
78 |
|
78 |
|
79 |
=cut |
79 |
=cut |
80 |
|
80 |
|
Lines 92-103
Read the manual, with examples.
Link Here
|
92 |
|
92 |
|
93 |
=item B<--verbose> |
93 |
=item B<--verbose> |
94 |
|
94 |
|
95 |
Send the "WHERE" clause generated by the collected C<--criteria> |
95 |
Send the "WHERE" clause generated by the collected C<--where> |
96 |
arguments, as well as items affected to Standard Out. |
96 |
arguments, as well as items affected to Standard Out. |
97 |
|
97 |
|
98 |
=item B<--criteria> |
98 |
=item B<--where> |
99 |
|
99 |
|
100 |
The C<--criteria> option may called multiple times. The following argument |
100 |
The C<--where> option may called multiple times. The following argument |
101 |
must be a syntactically valid SQL statement which is part of the C<WHERE> |
101 |
must be a syntactically valid SQL statement which is part of the C<WHERE> |
102 |
clause querying the items table. These are joined by C<AND>. |
102 |
clause querying the items table. These are joined by C<AND>. |
103 |
|
103 |
|
Lines 114-122
No items will be deleted unless the C<--commit> flag is present.
Link Here
|
114 |
|
114 |
|
115 |
The following is an example of this script: |
115 |
The following is an example of this script: |
116 |
|
116 |
|
117 |
delete_items.pl --criteria "items.withdrawn ! 0" --criteria "items.withdrawn_on < $(date --date="13 month ago" --rfc-3339=date)" --commit |
117 |
delete_items.pl --where "items.withdrawn ! 0" --where "items.withdrawn_on < $(date --date="13 month ago" --rfc-3339=date)" --commit |
118 |
|
118 |
|
119 |
delete_items.pl --criteria "itemlost >= '1'" --criteria "itemlost <='4'" --criteria "itemlost_on < '2014-04-28'" --commit |
119 |
delete_items.pl --where "itemlost >= '1'" --where "itemlost <='4'" --where "itemlost_on < '2014-04-28'" --commit |
120 |
|
120 |
|
121 |
=cut |
121 |
=cut |
122 |
|
122 |
|
123 |
- |
|
|