line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::DBI::Handle::Sybase; |
2
|
1
|
|
|
1
|
|
1372
|
use Jifty::DBI::Handle; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
@ISA = qw(Jifty::DBI::Handle); |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
39
|
use vars qw($VERSION @ISA $DBIHandle $DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
357
|
|
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 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 object with the error reported. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub insert { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $table = shift; |
35
|
0
|
|
|
|
|
|
my %pairs = @_; |
36
|
0
|
|
|
|
|
|
my $sth = $self->SUPER::insert( $table, %pairs ); |
37
|
0
|
0
|
|
|
|
|
if ( !$sth ) { |
38
|
0
|
|
|
|
|
|
return ($sth); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Can't select identity column if we're inserting the id by hand. |
42
|
0
|
0
|
|
|
|
|
unless ( $pairs{'id'} ) { |
43
|
0
|
|
|
|
|
|
my @row = $self->fetch_result('SELECT @@identity'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# TODO: Propagate Class::ReturnValue up here. |
46
|
0
|
0
|
|
|
|
|
unless ( $row[0] ) { |
47
|
0
|
|
|
|
|
|
return (undef); |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
$self->{'id'} = $row[0]; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
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
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
62
|
0
|
|
|
|
|
|
my $v = $self->SUPER::database_version(); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$v =~ s/\-(.*)$//; |
65
|
0
|
|
|
|
|
|
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
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
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
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
my $statementref = shift; |
98
|
0
|
|
|
|
|
|
my $collection = shift; |
99
|
0
|
|
|
|
|
|
my $table = $collection->table; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if ( $collection->_order_clause =~ /(?
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Don't know how to do ORDER BY when the DISTINCT is in a subquery |
104
|
0
|
|
|
|
|
|
warn |
105
|
|
|
|
|
|
|
"Query will contain duplicate rows; don't how how to ORDER BY across DISTINCT"; |
106
|
0
|
|
|
|
|
|
$$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
|
0
|
|
|
|
|
|
$$statementref |
112
|
|
|
|
|
|
|
= "SELECT main.* FROM ( SELECT DISTINCT main.id FROM $$statementref ) distinctquery, $table main WHERE (main.id = distinctquery.id) "; |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
$$statementref .= $collection->_group_clause; |
115
|
0
|
|
|
|
|
|
$$statementref .= $collection->_order_clause; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |