line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::DBI::Handle::Sybase; |
2
|
1
|
|
|
1
|
|
2009
|
use Jifty::DBI::Handle; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
@ISA = qw(Jifty::DBI::Handle); |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use vars qw($VERSION @ISA $DBIHandle $DEBUG); |
6
|
|
|
|
|
|
|
use strict; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Jifty::DBI::Handle::Sybase -- a Sybase specific Handle object |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module provides a subclass of L<Jifty::DBI::Handle> that |
17
|
|
|
|
|
|
|
compensates for some of the idiosyncrasies of Sybase. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 insert |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Takes a table name as the first argument and assumes that the rest of |
24
|
|
|
|
|
|
|
the arguments are an array of key-value pairs to be inserted. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
If the insert succeeds, returns the id of the insert, otherwise, |
27
|
|
|
|
|
|
|
returns a L<Class::ReturnValue> object with the error reported. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub insert { |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $table = shift; |
35
|
|
|
|
|
|
|
my %pairs = @_; |
36
|
|
|
|
|
|
|
my $sth = $self->SUPER::insert( $table, %pairs ); |
37
|
|
|
|
|
|
|
if ( !$sth ) { |
38
|
|
|
|
|
|
|
return ($sth); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Can't select identity column if we're inserting the id by hand. |
42
|
|
|
|
|
|
|
unless ( $pairs{'id'} ) { |
43
|
|
|
|
|
|
|
my @row = $self->fetch_result('SELECT @@identity'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# TODO: Propagate Class::ReturnValue up here. |
46
|
|
|
|
|
|
|
unless ( $row[0] ) { |
47
|
|
|
|
|
|
|
return (undef); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
$self->{'id'} = $row[0]; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
return ( $self->{'id'} ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 database_version |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return the database version, trimming off any -foo identifier |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub database_version { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $v = $self->SUPER::database_version(); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$v =~ s/\-(.*)$//; |
65
|
|
|
|
|
|
|
return ($v); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 case_sensitive |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns undef, since Sybase's searches are not case sensitive by default |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub case_sensitive { |
76
|
|
|
|
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
return (1); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub apply_limits { |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
my $statementref = shift; |
83
|
|
|
|
|
|
|
my $per_page = shift; |
84
|
|
|
|
|
|
|
my $first = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 distinct_query STATEMENTREF |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Takes an incomplete SQL SELECT statement and massages it to return a |
91
|
|
|
|
|
|
|
DISTINCT result set. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub distinct_query { |
96
|
|
|
|
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
my $statementref = shift; |
98
|
|
|
|
|
|
|
my $sb = shift; |
99
|
|
|
|
|
|
|
my $table = $sb->table; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
if ( $sb->_order_clause =~ /(?<!main)\./ ) { |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Don't know how to do ORDER BY when the DISTINCT is in a subquery |
104
|
|
|
|
|
|
|
warn |
105
|
|
|
|
|
|
|
"Query will contain duplicate rows; don't how how to ORDER BY across DISTINCT"; |
106
|
|
|
|
|
|
|
$$statementref = "SELECT main.* FROM $$statementref"; |
107
|
|
|
|
|
|
|
} else { |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Wrapper select query in a subselect as Sybase doesn't allow |
110
|
|
|
|
|
|
|
# DISTINCT against CLOB/BLOB column types. |
111
|
|
|
|
|
|
|
$$statementref |
112
|
|
|
|
|
|
|
= "SELECT main.* FROM ( SELECT DISTINCT main.id FROM $$statementref ) distinctquery, $table main WHERE (main.id = distinctquery.id) "; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
$$statementref .= $sb->_group_clause; |
115
|
|
|
|
|
|
|
$$statementref .= $sb->_order_clause; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Jesse Vincent, jesse@fsck.com |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L<Jifty::DBI>, L<Jifty::DBI::Handle>, L<DBD::Sybase> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |