| 1 | package Jifty::DBI::Handle::Sybase; | ||||||||||
| 2 | 1 | ▶ | use Jifty::DBI::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | @ISA = qw(Jifty::DBI::Handle); | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION @ISA $DBIHandle $DEBUG); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
insert: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 33 | |||||||||||
| 34 | 0 | my $table = shift; | |||||||||
| 35 | 0 | my %pairs = @_; | |||||||||
| 36 | 0 | my $sth = $self->SUPER::insert( $table, %pairs ); | |||||||||
| 37 | 0 | ▶ | if ( !$sth ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | return ($sth); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # Can't select identity column if we're inserting the id by hand. | ||||||||||
| 42 | 0 | ▶ | unless ( $pairs{'id'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | my @row = $self->fetch_result('SELECT @@identity'); | |||||||||
| 44 | |||||||||||
| 45 | # TODO: Propagate Class::ReturnValue up here. | ||||||||||
| 46 | 0 | ▶ | unless ( $row[0] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
database_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
case_sensitive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
distinct_query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 97 | 0 | my $statementref = shift; | |||||||||
| 98 | 0 | my $collection = shift; | |||||||||
| 99 | 0 | my $table = $collection->table; | |||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | if ( $collection->_order_clause =~ /(?<!main)\./ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 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 | ||||||||||