MSSQL/SQLMaker.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 83.3% 5 / 6 Conditioncond 58.3% 7 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 84.0% 58 / 69 CC 8 SCAR 11.4
CC
8
Cov
86%
_nulls_expr
6.6
_chunkify_order_by
4.0
_render_nulls_key
2.0
CRAP 3.1
« MSSQL/Diff/ForeignKey.pm ↑ Summary MSSQL/Storage/DateTime/Format.pm »
1 package DBIO::MSSQL::SQLMaker;
2 # ABSTRACT: MSSQL-specific SQL generation for DBIO
3  
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 our $VERSION = '0.900007';
7  
8 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 ▶use base qw( DBIO::SQLMaker );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13  
14 63 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 63 my $self = shift->next::method(@_);
16  
17 # copy first: the table of render ops may be shared with other makers
18 $self->{render_op} = {
19 63 %{ $self->{render_op} },
20 nulls_first => '_render_op_nulls',
21 nulls_last => '_render_op_nulls',
22 };
23  
24 63 return $self;
25 }
26  
27  
28 10 ▶sub _render_op_nulls {
Subroutine _render_op_nulls: called CC=1 SCAR=0.0
29 10 my ($self, $op, $args) = @_;
30 10 my ($node) = @$args;
31  
32 10 return $self->join_query_parts(', ',
33 $self->_render_nulls_key($op, $node),
34 $node,
35 );
36 }
37  
38  
39 60 ▶sub _chunkify_order_by {
Subroutine _chunkify_order_by: called CC=4 SCAR=13.9
40 60 my ($self, $expanded) = @_;
41  
42 60 ▶ if (ref $expanded eq 'HASH' and ref $expanded->{-op} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expanded eq "HASH" and ref $expanded->{"-op"} eq "ARRAY" and $expanded->{"-op"}[0] =~ /\Anulls_(?:first|last)\z/) 16 44 60
Condition83%5/6
ref $expanded eq "HASH" and ref $expanded->{"-op"} eq "ARRAY" and $expanded->{"-op"}[0] =~ /\Anulls_(?:first|last)\z/
!ll&&!rl&&r
73716
ref $expanded eq "HASH" and ref $expanded->{"-op"} eq "ARRAY"
!ll&&!rl&&r
0753
MC/DC66%2/3
ref $expanded eq "HASH" and ref $expanded->{"-op"} eq "ARRAY" and $expanded->{"-op"}[0] =~ /\Anulls_(?:first|last)\z/
ref $expanded eq "HASH" ref $expanded->{"-op"} eq "ARRAY" $expanded->{"-op"}[0] =~ /\Anulls_(?:first|last)\z/
Truth table75%3/4
A and B and C
A= ref $expanded eq "HASH"B= ref $expanded->{"-op"} eq "ARRAY"C= $expanded->{"-op"}[0] =~ /\Anulls_(?:first|last)\z/
ABCresult
0XX0
10X0
1100
1111
43 and $expanded->{-op}[0] =~ /\Anulls_(?:first|last)\z/) {
44 16 my ($op, $node) = @{ $expanded->{-op} };
45 return (
46 16 $self->_render_nulls_key($op, $node),
47 $self->_chunkify_order_by($node),
48 );
49 }
50  
51 44 return $self->next::method($expanded);
52 }
53  
54  
55 26 ▶sub _nulls_expr {
Subroutine _nulls_expr: called CC=4 SCAR=18.9
56 26 my ($self, $node) = @_;
57 return $node->{-op}[1]
58 if ref $node eq 'HASH' and ref $node->{-op} eq 'ARRAY'
59 26 ▶ and $node->{-op}[0] =~ /\A(?:asc|desc)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY" and $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/ 26 0 26
Condition33%2/6
ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY" and $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
!ll&&!rl&&r
0026
ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY"
!ll&&!rl&&r
0026
MC/DC0%0/3
ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY" and $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
ref $node eq "HASH" ref $node->{"-op"} eq "ARRAY" $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
Truth table25%1/4
A and B and C
A= ref $node eq "HASH"B= ref $node->{"-op"} eq "ARRAY"C= $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
ABCresult
0XX0
10X0
1100
1111
60 0 return $node;
61 }
62  
63  
64 26 ▶sub _render_nulls_key {
Subroutine _render_nulls_key: called CC=2 SCAR=6.9
65 26 my ($self, $op, $node) = @_;
66 26 ▶ my $then_else = $op eq 'nulls_first' ? 'THEN 0 ELSE 1 END' : 'THEN 1 ELSE 0 END';
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'nulls_first' ? : 17 9 26
67 26 return $self->join_query_parts(' ',
68 'CASE WHEN', { -op => [ 'is_null', $self->_nulls_expr($node) ] }, "$then_else ASC",
69 );
70 }
71  
72  
73 8 ▶sub apply_limit {
Subroutine apply_limit: called CC=1 SCAR=0.0
Pod documented
74 8 my ($self, $sql, $rs_attrs, $rows, $offset) = @_;
75 8 return $self->_RowNumberOver($sql, $rs_attrs, $rows, $offset);
76 }
77  
78 #
79 # MSSQL does not support ... OVER() ... RNO limits
80 #
81 2 ▶sub _rno_default_order {
Subroutine _rno_default_order: called CC=1 SCAR=0.0
82 2 return \ '(SELECT(1))';
83 }
84  
85  
86 17 1;
87  
88 __END__
« MSSQL/Diff/ForeignKey.pm ↑ Summary MSSQL/Storage/DateTime/Format.pm »