File Coverage

blib/lib/Jifty/DBI/Handle/Informix.pm
Criterion Covered Total %
statement 9 41 21.9
branch 0 10 0.0
condition n/a
subroutine 3 8 37.5
pod 5 5 100.0
total 17 64 26.5


line stmt bran cond sub pod time code
1             package Jifty::DBI::Handle::Informix;
2 1     1   977 use Jifty::DBI::Handle;
  1         2  
  1         6  
3             @ISA = qw(Jifty::DBI::Handle);
4              
5 1     1   47 use vars qw($VERSION @ISA $DBIHandle $DEBUG);
  1         1  
  1         67  
6 1     1   5 use strict;
  1         2  
  1         396  
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     0 1   my $self = shift;
35              
36 0           my $sth = $self->SUPER::insert(@_);
37 0 0         if ( !$sth ) {
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 0         warn "$self no row id returned on row creation" unless ( $self->{'id'} );
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     0 1   my $self = shift;
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     0 1   my $self = shift;
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 0         if ($per_page) {
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     0 1   my $self = shift;
85 0 0         if ( $self->dbh ) {
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     0 1   my $self = shift;
103 0           my $statementref = shift;
104 0           my $collection = shift;
105 0           my $table = $collection->table;
106              
107 0 0         if ( $collection->_order_clause =~ /(?
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;
125              
126             __END__