| 1 | package DBIx::SearchBuilder::Handle::Informix; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base qw(DBIx::SearchBuilder::Handle); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | DBIx::SearchBuilder::Handle::Informix - An Informix specific Handle object | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | This module provides a subclass of DBIx::SearchBuilder::Handle that | ||||||||||||||||||||||||||||
| 18 | compensates for some of the idiosyncrasies of Informix. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head2 Insert | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 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. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | If the insert succeeds, returns the id of the insert, otherwise, returns | ||||||||||||||||||||||||||||
| 30 | a Class::ReturnValue object with the error reported. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub Insert { | ||||||||||||||||||||||||||
|
Subroutine
Insert: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $sth = $self->SUPER::Insert(@_); | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (!$sth) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | print "no sth! (".$self->dbh->{ix_sqlerrd}[1].")\n"; | |||||||||||||||||||||||||||
| 40 | 0 | return ($sth); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | $self->{id}=$self->dbh->{ix_sqlerrd}[1]; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | warn "$self no row id returned on row creation" unless ($self->{'id'}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | return( $self->{'id'}); #Add Succeded. return the id | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head2 CaseSensitive | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Returns 1, since Informix's searches are case sensitive by default | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub CaseSensitive { | ||||||||||||||||||||||||||
|
Subroutine
CaseSensitive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 0 | return(1); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head2 BuildDSN | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Builder for Informix DSNs. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub BuildDSN { | ||||||||||||||||||||||||||
|
Subroutine
BuildDSN: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | 0 | my %args = ( | |||||||||||||||||||||||||||
| 71 | Driver => undef, | ||||||||||||||||||||||||||||
| 72 | Database => undef, | ||||||||||||||||||||||||||||
| 73 | Host => undef, | ||||||||||||||||||||||||||||
| 74 | Port => undef, | ||||||||||||||||||||||||||||
| 75 | SID => undef, | ||||||||||||||||||||||||||||
| 76 | RequireSSL => undef, | ||||||||||||||||||||||||||||
| 77 | @_ | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $dsn = "dbi:$args{'Driver'}:"; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $dsn .= "$args{'Database'}" if (defined $args{'Database'} && $args{'Database'}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args{"Database"} and $args{"Database"}
MC/DC0%0/2
defined $args{"Database"} and $args{"Database"}
defined $args{"Database"}
$args{"Database"}
Truth table0%0/3
A and B
A= defined $args{"Database"}B= $args{"Database"}
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | $self->{'dsn'}= $dsn; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head2 ApplyLimits STATEMENTREF ROWS_PER_PAGE FIRST_ROW | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | takes an SQL SELECT statement and massages it to return ROWS_PER_PAGE starting with FIRST_ROW; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub ApplyLimits { | ||||||||||||||||||||||||||
|
Subroutine
ApplyLimits: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | 0 | my $statementref = shift; | |||||||||||||||||||||||||||
| 98 | 0 | my $per_page = shift; | |||||||||||||||||||||||||||
| 99 | 0 | my $first = shift; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # XXX TODO THIS only works on the FIRST page of results. that's a bug | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($per_page) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | $$statementref =~ s[^\s*SELECT][SELECT FIRST $per_page]i; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub Disconnect { | ||||||||||||||||||||||||||
|
Subroutine
Disconnect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($self->dbh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | my $status = $self->dbh->disconnect(); | |||||||||||||||||||||||||||
| 112 | 0 | $self->dbh( undef); | |||||||||||||||||||||||||||
| 113 | 0 | return $status; | |||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||
| 115 | 0 | return; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head2 DistinctQuery STATEMENTREF | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | takes an incomplete SQL SELECT statement and massages it to return a DISTINCT result set. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub DistinctQuery { | ||||||||||||||||||||||||||
|
Subroutine
DistinctQuery: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 129 | 0 | my $statementref = shift; | |||||||||||||||||||||||||||
| 130 | 0 | my $sb = shift; | |||||||||||||||||||||||||||
| 131 | 0 | my $table = $sb->Table; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($sb->_OrderClause =~ /(?<!main)\./) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | # Don't know how to do ORDER BY when the DISTINCT is in a subquery | ||||||||||||||||||||||||||||
| 135 | 0 | warn "Query will contain duplicate rows; don't how how to ORDER BY across DISTINCT"; | |||||||||||||||||||||||||||
| 136 | 0 | $$statementref = "SELECT main.* FROM $$statementref"; | |||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||
| 138 | # Wrapper select query in a subselect as Informix doesn't allow | ||||||||||||||||||||||||||||
| 139 | # DISTINCT against CLOB/BLOB column types. | ||||||||||||||||||||||||||||
| 140 | 0 | $$statementref = "SELECT * FROM $table main WHERE id IN ( SELECT DISTINCT main.id FROM $$statementref )"; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 0 | $$statementref .= $sb->_GroupClause; | |||||||||||||||||||||||||||
| 143 | 0 | $$statementref .= $sb->_OrderClause; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | 1; | |||||||||||||||||||||||||||