Gantry/Utils/SQL.pm

filter: Statementstmt 14.0% 7 / 50 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 22.2% 2 / 9 Podpod 100% 7 / 7 totaltotal 15.2% 16 / 105 CC 16 SCAR 29.4
CC
16
Cov
8%
sql_bool
42.0
sql_update
20.0
sql_insert
12.0
CRAP 19.0
« Gantry/Utils/Crypt.pm ↑ Summary Gantry/State/Exceptions.pm »
1 package Gantry::Utils::SQL;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 ############################################################
7 # Variables #
8 ############################################################
9 ############################################################
10 # Functions #
11 ############################################################
12 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
13 0 my ( $class, $opt ) = @_;
14  
15 0 my $self = {};
16 0 bless( $self, $class );
17  
18 # populate self with data from site
19 0 return( $self );
20  
21 } # end new
22  
23 #-------------------------------------------------
24 # $sql_helper->sql_bool( $bool_string )
25 #-------------------------------------------------
26 0 ▶sub sql_bool {
Subroutine sql_bool: not called CC=6 SCAR=37.4
Pod documented
27 0 my( $self, $input ) = shift;
28  
29 0 ▶ return( 'FALSE' ) if ( ( ! defined $input ) || ( ! length $input ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input and length $input 0 0 0
Condition0%0/3
defined $input and length $input
!ll&&!rl&&r
000
MC/DC0%0/2
defined $input and length $input
defined $input length $input
Truth table0%0/3
A and B
A= defined $inputB= length $input
ABresult
0X0
100
111
30  
31 0 ▶ if ( $input =~ /^(t|y|1)$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($input =~ /^(t|y|1)$/i) { } 0 0 0
elsif ($input =~ /^(f|n|0)$/i) { } 0 0 0
elsif (defined $input) { } 0 0 0
32 0 return( 'TRUE' );
33 }
34 elsif ( $input =~ /^(f|n|0)$/i ) {
35 0 return( 'FALSE' );
36 }
37 elsif ( defined $input ) {
38 0 return( 'TRUE' );
39 }
40 else {
41 0 return( 'FALSE' );
42 }
43  
44 } # END sql_bool
45  
46 #-------------------------------------------------
47 # $sql_helper->sql_insert( $table, %data )
48 #-------------------------------------------------
49 0 ▶sub sql_insert {
Subroutine sql_insert: not called CC=3 SCAR=24.8
Pod documented
50 0 my ( $self, $table, @vals ) = @_;
51  
52 0 my ( @fields, @values );
53  
54 0 ▶ while ( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 0 0 0
55 0 push ( @fields, shift( @vals ) );
56
57 0 ▶ if ( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) { } 0 0 0
58 0 push( @values, shift( @vals ) );
59 }
60 else {
61 0 confess( 'Error: Incorrect number of arguements.' );
62 }
63 }
64  
65 0 return( "INSERT INTO $table ( ". join( ', ', @fields ). ' ) VALUES ( '.
66 join( ', ', @values ). ' )' );
67 } # END sql_insert
68  
69 #-------------------------------------------------
70 # $sql_helper->sql_num( $number )
71 #-------------------------------------------------
72 0 ▶sub sql_num {
Subroutine sql_num: not called CC=3 SCAR=24.8
Pod documented
73 0 my ( $self, $number ) = ( shift, shift );
74  
75 0 ▶ return( 'NULL' ) if ( ( ! defined $number ) || ! length ( $number) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number and length $number 0 0 0
Condition0%0/3
defined $number and length $number
!ll&&!rl&&r
000
MC/DC0%0/2
defined $number and length $number
defined $number length $number
Truth table0%0/3
A and B
A= defined $numberB= length $number
ABresult
0X0
100
111
76  
77 0 $number =~ s/\\/\\\\/g;
78 0 $number =~ s/\'/\\'/g;
79
80 0 return( "'$number'" );
81 } # END sql_num
82  
83 #-------------------------------------------------
84 # $sql_helper->sql_str( $string )
85 #-------------------------------------------------
86 0 ▶sub sql_str {
Subroutine sql_str: not called CC=3 SCAR=24.8
Pod documented
87 0 my( $self, $string ) = ( shift, shift );
88  
89 0 ▶ return( "''" ) if ( !defined( $string ) || ! length( $string ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string and length $string 0 0 0
Condition0%0/3
defined $string and length $string
!ll&&!rl&&r
000
MC/DC0%0/2
defined $string and length $string
defined $string length $string
Truth table0%0/3
A and B
A= defined $stringB= length $string
ABresult
0X0
100
111
90  
91 0 $string =~ s/\\/\\\\/g;
92 0 $string =~ s/\'/\\'/g;
93  
94 0 return( "'$string'" );
95 } # END sql_str
96  
97 #-------------------------------------------------
98 # $sql_helper->sql_update( $table, $clause, $data )
99 #-------------------------------------------------
100 0 ▶sub sql_update {
Subroutine sql_update: not called CC=4 SCAR=30.0
Pod documented
101 0 my ( $self, $table, $clause, @vals ) = @_;
102  
103 0 ▶ $clause = '' if ( ! defined $clause );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $clause 0 0 0
104  
105 0 my @updates;
106  
107 0 ▶ while ( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 0 0 0
108 0 my $field = shift( @vals );
109
110 0 ▶ if ( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) { } 0 0 0
111 0 push( @updates, "$field=". shift( @vals ) );
112 }
113 else {
114 0 confess( 'Error: Incorrect number of arguements.' );
115 }
116 }
117  
118 0 return( "UPDATE $table SET ". join( ', ', @updates ). ' '. $clause );
119 } # END sql_update
120  
121 #-------------------------------------------------
122 # $sql_helper->sql_quote( $string )
123 #-------------------------------------------------
124 0 ▶sub sql_quote {
Subroutine sql_quote: not called CC=2 SCAR=17.9
Pod documented
125 0 my ( $self, $sql ) = ( shift, shift );
126  
127 0 ▶ return( '' ) if ( ! defined $sql );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sql 0 0 0
128  
129 0 $sql =~ s/\\/\\\\/g;
130 0 $sql =~ s/'/''/g;
131  
132 0 return( $sql );
133 } # END sql_quote
134  
135 # EOF
136 3 1;
137  
138 __END__
« Gantry/Utils/Crypt.pm ↑ Summary Gantry/State/Exceptions.pm »