dbMan/Extension/CountPost.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 57 CC 6 SCAR 32.6
CC
6
Cov
0%
handle_action
42.0
IDENTIFICATION
2.0
preference
2.0
CRAP 26.0
1 package DBIx::dbMan::Extension::CountPost;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5  
6 our $VERSION = '0.02';
7  
8 1;
9  
10 sub IDENTIFICATION { return "000001-000080-000002"; }
11  
12 sub preference { return 90; }
13  
14 sub handle_action {
15 my ($obj,%action) = @_;
16  
17 $action{processed} = 1;
18 if ($action{count_process} eq '1') {
19 delete $action{processed};
20 delete $action{count_process};
21 my $oldaction = $action{action};
22 $action{action} = 'COUNT';
23 $action{sql} = uc $action{sql};
24 $action{sql} =~ s/SELECT COUNT\(\*\) POCET FROM //i;
25 $action{error_output} .= "Table $action{sql} does not exists.\n" if $oldaction eq 'OUTPUT';
26 return %action if $oldaction ne 'SQL_RESULT';
27  
28 my $result = $action{result};
29 $action{count_rows} = $result->[0][0];
30 $action{action} = 'SQL';
31 $action{sql} = 'SELECT * FROM '.$action{sql}.' WHERE 0 = 1';
32 $action{count_process} = '2';
33 } elsif ($action{count_process} eq '2') {
34 delete $action{processed};
35 delete $action{count_process};
36 my $oldaction = $action{action};
37 $action{action} = 'COUNT';
38 $action{sql} = uc $action{sql};
39 $action{sql} =~ s/SELECT \* FROM //i;
40 $action{sql} =~ s/ WHERE 0 = 1//i;
41 return %action if $oldaction ne 'SQL_RESULT';
42  
43 my $result = $action{result};
44 $action{count_result}->{$action{sql}}{rows} = $action{count_rows};
45 $action{count_result}->{$action{sql}}{cols} = scalar @{$action{fieldnames}};
46 }
47  
48 return %action;
49 }