File Coverage

blib/lib/Class/DBI/FreeTDS.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 8 0.0
condition 0 7 0.0
subroutine 3 4 75.0
pod n/a
total 12 44 27.2


line stmt bran cond sub pod time code
1             package Class::DBI::FreeTDS;
2              
3             =head1 NAME
4              
5             Class::DBI::FreeTDS - Extensions to Class::DBI for users of FreeTDS
6              
7             =head1 SYNOPSIS
8              
9             package Music::DBI;
10             use base 'Class::DBI::FreeTDS';
11              
12             Music::DBI->set_db('Main', 'dbi:Sybase:server=$server', 'username', 'password');
13              
14             package Artist;
15             use base 'Music::DBI';
16             __PACKAGE__->set_up_table('Artist');
17            
18             # ... see the Class::DBI documentation for details on Class::DBI usage
19              
20             =head1 DESCRIPTION
21              
22             This is an extension to Class::DBI that compensates for FreeTDS' current lack of placeholder support.
23              
24             Instead of setting Class::DBI as your base class, use this.
25              
26             =head1 BUGS
27              
28             This is an ugly hack.
29              
30             =head1 AUTHOR
31              
32             Dan Sully Edaniel@cpan.orgE
33              
34             =head1 SEE ALSO
35              
36             L, L, http://www.freetds.org/
37              
38             =cut
39              
40 1     1   953 use strict;
  1         11  
  1         47  
41 1     1   7 use base 'Class::DBI::Sybase';
  1         2  
  1         97  
42              
43 1     1   1585 use vars qw($VERSION);
  1         3  
  1         341  
44             $VERSION = '0.1';
45              
46             # This is to fix MSSQL/TDS brokenness with placeholders. Ugh.
47             # Inline them instead. This overrides a Class::DBI method.
48             sub _do_search {
49 0     0     my $proto = shift;
50 0   0       my $search_type = shift || '';
51 0           my @args = @_;
52 0   0       my $class = ref $proto || $proto;
53              
54 0 0         @args = %{ $args[0] } if ref $args[0] eq "HASH";
  0            
55 0           my (@cols, @vals);
56 0 0         my $search_opts = @args % 2 ? pop @args : {};
57 0           my @frag = ();
58              
59 0           while (my ($col, $val) = splice @args, 0, 2) {
60 0 0         $col = $class->find_column($col) or $class->croak("$col is not a column of $class");
61 0   0       $val = $class->_deflated_column($col, $val) || next;
62              
63 0           push @frag, "$col $search_type $val";
64             }
65              
66 0           my $frag = join(' AND ', @frag);
67 0 0         $frag .= " ORDER BY $search_opts->{order_by}" if $search_opts->{order_by};
68              
69 0           return $class->sth_to_objects($class->sql_Retrieve($frag));
70             }
71              
72             1;
73              
74             __END__