Commit | Line | Data |
057db5ce |
1 | package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars; |
5608593e |
2 | |
3 | use base qw/ |
4 | DBIx::Class::Storage::DBI::NoBindVars |
057db5ce |
5 | DBIx::Class::Storage::DBI::Sybase::ASE |
5608593e |
6 | /; |
322b7a6b |
7 | use mro 'c3'; |
6298a324 |
8 | use List::Util 'first'; |
9 | use Scalar::Util 'looks_like_number'; |
10 | use namespace::clean; |
5608593e |
11 | |
37b17a93 |
12 | sub _init { |
9b3dabe0 |
13 | my $self = shift; |
14 | $self->disable_sth_caching(1); |
322b7a6b |
15 | $self->_identity_method('@@IDENTITY'); |
37b17a93 |
16 | $self->next::method (@_); |
9b3dabe0 |
17 | } |
18 | |
322b7a6b |
19 | sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method } |
6b1f5ef7 |
20 | |
6298a324 |
21 | my $number = sub { looks_like_number $_[0] }; |
0c449973 |
22 | |
b88bf40a |
23 | my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x }; |
24 | |
b55e97a7 |
25 | my %noquote = ( |
b88bf40a |
26 | int => sub { $_[0] =~ /^ [-+]? \d+ \z/x }, |
0c449973 |
27 | bit => => sub { $_[0] =~ /^[01]\z/ }, |
b88bf40a |
28 | money => sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x }, |
0c449973 |
29 | float => $number, |
30 | real => $number, |
31 | double => $number, |
b88bf40a |
32 | decimal => $decimal, |
33 | numeric => $decimal, |
b55e97a7 |
34 | ); |
0c1bedfc |
35 | |
80007f97 |
36 | sub interpolate_unquoted { |
0c1bedfc |
37 | my $self = shift; |
38 | my ($type, $value) = @_; |
39 | |
7d17f469 |
40 | return $self->next::method(@_) if not defined $value or not defined $type; |
bbdc039b |
41 | |
6298a324 |
42 | if (my $key = first { $type =~ /$_/i } keys %noquote) { |
80007f97 |
43 | return 1 if $noquote{$key}->($value); |
44 | } |
45 | elsif ($self->is_datatype_numeric($type) && $number->($value)) { |
46 | return 1; |
17d750d7 |
47 | } |
7d17f469 |
48 | |
0c1bedfc |
49 | return $self->next::method(@_); |
50 | } |
51 | |
166c6561 |
52 | sub _prep_interpolated_value { |
e06ad5d5 |
53 | my ($self, $type, $value) = @_; |
54 | |
55 | if ($type =~ /money/i && defined $value) { |
0ac07712 |
56 | # change a ^ not followed by \$ to a \$ |
57 | $value =~ s/^ (?! \$) /\$/x; |
e06ad5d5 |
58 | } |
59 | |
60 | return $value; |
61 | } |
62 | |
5608593e |
63 | 1; |
7e8cecc1 |
64 | |
65 | =head1 NAME |
66 | |
057db5ce |
67 | DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for |
68 | Sybase ASE without placeholder support |
7e8cecc1 |
69 | |
70 | =head1 DESCRIPTION |
71 | |
48580715 |
72 | If you're using this driver then your version of Sybase or the libraries you |
73 | use to connect to it do not support placeholders. |
22b3249c |
74 | |
7e8cecc1 |
75 | You can also enable this driver explicitly using: |
76 | |
77 | my $schema = SchemaClass->clone; |
057db5ce |
78 | $schema->storage_type('::DBI::Sybase::ASE::NoBindVars'); |
7e8cecc1 |
79 | $schema->connect($dsn, $user, $pass, \%opts); |
80 | |
81 | See the discussion in L<< DBD::Sybase/Using ? Placeholders & bind parameters to |
82 | $sth->execute >> for details on the pros and cons of using placeholders. |
83 | |
84 | One advantage of not using placeholders is that C<select @@identity> will work |
48580715 |
85 | for obtaining the last insert id of an C<IDENTITY> column, instead of having to |
e97a6ee2 |
86 | do C<select max(col)> in a transaction as the base Sybase driver does. |
7e8cecc1 |
87 | |
88 | When using this driver, bind variables will be interpolated (properly quoted of |
89 | course) into the SQL query itself, without using placeholders. |
90 | |
91 | The caching of prepared statements is also explicitly disabled, as the |
92 | interpolation renders it useless. |
93 | |
94 | =head1 AUTHORS |
95 | |
96 | See L<DBIx::Class/CONTRIBUTORS>. |
97 | |
98 | =head1 LICENSE |
99 | |
100 | You may distribute this code under the same terms as Perl itself. |
101 | |
102 | =cut |
103 | # vim:sts=2 sw=2: |