File Coverage

blib/lib/DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm
Criterion Covered Total %
statement 18 35 51.4
branch 0 10 0.0
condition 0 9 0.0
subroutine 6 10 60.0
pod 1 1 100.0
total 25 65 38.4


line stmt bran cond sub pod time code
1             package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars;
2              
3 2     2   1123 use warnings;
  2         6  
  2         65  
4 2     2   10 use strict;
  2         4  
  2         46  
5              
6 2         384 use base qw/
7             DBIx::Class::Storage::DBI::NoBindVars
8             DBIx::Class::Storage::DBI::Sybase::ASE
9 2     2   8 /;
  2         5  
10 2     2   14 use mro 'c3';
  2         4  
  2         12  
11 2     2   52 use Scalar::Util 'looks_like_number';
  2         16  
  2         93  
12 2     2   15 use namespace::clean;
  2         4  
  2         11  
13              
14             sub _init {
15 0     0     my $self = shift;
16 0           $self->disable_sth_caching(1);
17 0           $self->_identity_method('@@IDENTITY');
18 0           $self->next::method (@_);
19             }
20              
21 0     0     sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method }
22              
23             my $number = sub { looks_like_number $_[0] };
24              
25             my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x };
26              
27             my %noquote = (
28             int => sub { $_[0] =~ /^ [-+]? \d+ \z/x },
29             bit => => sub { $_[0] =~ /^[01]\z/ },
30             money => sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x },
31             float => $number,
32             real => $number,
33             double => $number,
34             decimal => $decimal,
35             numeric => $decimal,
36             );
37              
38             sub interpolate_unquoted {
39 0     0 1   my $self = shift;
40 0           my ($type, $value) = @_;
41              
42 0 0 0       return $self->next::method(@_) if not defined $value or not defined $type;
43              
44 0 0 0       if (my ($key) = grep { $type =~ /$_/i } keys %noquote) {
  0 0          
45 0 0         return 1 if $noquote{$key}->($value);
46             }
47             elsif ($self->is_datatype_numeric($type) && $number->($value)) {
48 0           return 1;
49             }
50              
51 0           return $self->next::method(@_);
52             }
53              
54             sub _prep_interpolated_value {
55 0     0     my ($self, $type, $value) = @_;
56              
57 0 0 0       if ($type =~ /money/i && defined $value) {
58             # change a ^ not followed by \$ to a \$
59 0           $value =~ s/^ (?! \$) /\$/x;
60             }
61              
62 0           return $value;
63             }
64              
65             1;
66              
67             =head1 NAME
68              
69             DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for
70             Sybase ASE without placeholder support
71              
72             =head1 DESCRIPTION
73              
74             If you're using this driver then your version of Sybase or the libraries you
75             use to connect to it do not support placeholders.
76              
77             You can also enable this driver explicitly using:
78              
79             my $schema = SchemaClass->clone;
80             $schema->storage_type('::DBI::Sybase::ASE::NoBindVars');
81             $schema->connect($dsn, $user, $pass, \%opts);
82              
83             See the discussion in
84             L<< DBD::Sybase/Using ? Placeholders & bind parameters to $sth->execute >>
85             for details on the pros and cons of using placeholders with this particular
86             driver.
87              
88             One advantage of not using placeholders is that C
89             for obtaining the last insert id of an C column, instead of having to
90             do C
91              
92             When using this driver, bind variables will be interpolated (properly quoted of
93             course) into the SQL query itself, without using placeholders.
94              
95             The caching of prepared statements is also explicitly disabled, as the
96             interpolation renders it useless.
97              
98             =head1 FURTHER QUESTIONS?
99              
100             Check the list of L.
101              
102             =head1 COPYRIGHT AND LICENSE
103              
104             This module is free software L
105             by the L. You can
106             redistribute it and/or modify it under the same terms as the
107             L.