DBI/Handle/Informix.pm

filter: Statementstmt 25.5% 11 / 43 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 28.7% 19 / 66 CC 6 SCAR 17.8
CC
6
Cov
21%
insert
12.0
apply_limits
6.0
disconnect
6.0
CRAP 5.9
« DBI/Collection/Unique.pm ↑ Summary DBI/Record/Cachable.pm »
1 package Jifty::DBI::Handle::Informix;
2 1 ▶use Jifty::DBI::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 @ISA = qw(Jifty::DBI::Handle);
4  
5 1 ▶use vars qw($VERSION @ISA $DBIHandle $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Jifty::DBI::Handle::Informix - An Informix specific Handle object
11  
12 =head1 SYNOPSIS
13  
14  
15 =head1 DESCRIPTION
16  
17 This module provides a subclass of Jifty::DBI::Handle that
18 compensates for some of the idiosyncrasies of Informix.
19  
20 =head1 METHODS
21  
22 =cut
23  
24 =head2 insert
25  
26 Takes a table name as the first argument and assumes that the rest of the arguments are an array of key-value pairs to be inserted.
27  
28 If the insert succeeds, returns the id of the insert, otherwise, returns
29 a Class::ReturnValue object with the error reported.
30  
31 =cut
32  
33 sub insert {
34 0 ▶ my $self = shift;
Subroutine insert: not called CC=3 SCAR=24.8
Pod documented
35  
36 0 my $sth = $self->SUPER::insert(@_);
37 0 ▶ if ( !$sth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth) 0 0 0
38 0 print "no sth! (" . $self->dbh->{ix_sqlerrd}[1] . ")\n";
39 0 return ($sth);
40 }
41  
42 0 $self->{id} = $self->dbh->{ix_sqlerrd}[1];
43 0 ▶ warn "$self no row id returned on row creation" unless ( $self->{'id'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"id"} 0 0 0
44 0 return ( $self->{'id'} ); #Add Succeded. return the id
45 }
46  
47 =head2 case_sensitive
48  
49 Returns 1, since Informix's searches are case sensitive by default
50  
51 =cut
52  
53 sub case_sensitive {
54 0 ▶ my $self = shift;
Subroutine case_sensitive: not called CC=1 SCAR=6.9
Pod documented
55 0 return (1);
56 }
57  
58 =head2 apply_limits STATEMENTREF ROWS_PER_PAGE FIRST_ROW
59  
60 takes an SQL SELECT statement and massages it to return ROWS_PER_PAGE starting with FIRST_ROW;
61  
62  
63 =cut
64  
65 sub apply_limits {
66 0 ▶ my $self = shift;
Subroutine apply_limits: not called CC=2 SCAR=17.9
Pod documented
67 0 my $statementref = shift;
68 0 my $per_page = shift;
69 0 my $first = shift;
70  
71 # XXX TODO THIS only works on the FIRST page of results. that's a bug
72 0 ▶ if ($per_page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($per_page) 0 0 0
73 0 $$statementref =~ s[^\s*SELECT][SELECT FIRST $per_page]i;
74 }
75 }
76  
77 =head2 disconnect
78  
79 Disconnects and removes the reference to the handle for Informix.
80  
81 =cut
82  
83 sub disconnect {
84 0 ▶ my $self = shift;
Subroutine disconnect: not called CC=2 SCAR=17.9
Pod documented
85 0 ▶ if ( $self->dbh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dbh) { } 0 0 0
86 0 my $status = $self->dbh->disconnect();
87 0 $self->dbh(undef);
88 0 return $status;
89 } else {
90 0 return;
91 }
92 }
93  
94 =head2 distinct_query STATEMENTREF
95  
96 takes an incomplete SQL SELECT statement and massages it to return a DISTINCT result set.
97  
98  
99 =cut
100  
101 sub distinct_query {
102 0 ▶ my $self = shift;
Subroutine distinct_query: not called CC=2 SCAR=17.9
Pod documented
103 0 my $statementref = shift;
104 0 my $collection = shift;
105 0 my $table = $collection->table;
106  
107 0 ▶ if ( $collection->_order_clause =~ /(?<!main)\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($collection->_order_clause =~ /(?<!main)\./) { } 0 0 0
108  
109 # Don't know how to do ORDER BY when the DISTINCT is in a subquery
110 0 warn
111 "Query will contain duplicate rows; don't how how to ORDER BY across DISTINCT";
112 0 $$statementref = "SELECT main.* FROM $$statementref";
113 } else {
114  
115 # Wrapper select query in a subselect as Informix doesn't allow
116 # DISTINCT against CLOB/BLOB column types.
117 0 $$statementref
118 = "SELECT * FROM $table main WHERE id IN ( SELECT DISTINCT main.id FROM $$statementref )";
119 }
120 0 $$statementref .= $collection->_group_clause;
121 0 $$statementref .= $collection->_order_clause;
122 }
123  
124 1 1;
125  
126 __END__
127  
128 =head1 AUTHOR
129  
130 Oliver Tappe, oliver@akso.de
131  
132 =head1 SEE ALSO
133  
134 perl(1), Jifty::DBI
135  
136 =cut
« DBI/Collection/Unique.pm ↑ Summary DBI/Record/Cachable.pm »