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