Commit | Line | Data |
057db5ce |
1 | package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars; |
5608593e |
2 | |
4a233f30 |
3 | use warnings; |
4 | use strict; |
5 | |
5608593e |
6 | use base qw/ |
7 | DBIx::Class::Storage::DBI::NoBindVars |
057db5ce |
8 | DBIx::Class::Storage::DBI::Sybase::ASE |
5608593e |
9 | /; |
322b7a6b |
10 | use mro 'c3'; |
6298a324 |
11 | use Scalar::Util 'looks_like_number'; |
12 | use namespace::clean; |
5608593e |
13 | |
37b17a93 |
14 | sub _init { |
9b3dabe0 |
15 | my $self = shift; |
16 | $self->disable_sth_caching(1); |
322b7a6b |
17 | $self->_identity_method('@@IDENTITY'); |
37b17a93 |
18 | $self->next::method (@_); |
9b3dabe0 |
19 | } |
20 | |
322b7a6b |
21 | sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method } |
6b1f5ef7 |
22 | |
6298a324 |
23 | my $number = sub { looks_like_number $_[0] }; |
0c449973 |
24 | |
b88bf40a |
25 | my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x }; |
26 | |
b55e97a7 |
27 | my %noquote = ( |
b88bf40a |
28 | int => sub { $_[0] =~ /^ [-+]? \d+ \z/x }, |
0c449973 |
29 | bit => => sub { $_[0] =~ /^[01]\z/ }, |
b88bf40a |
30 | money => sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x }, |
0c449973 |
31 | float => $number, |
32 | real => $number, |
33 | double => $number, |
b88bf40a |
34 | decimal => $decimal, |
35 | numeric => $decimal, |
b55e97a7 |
36 | ); |
0c1bedfc |
37 | |
80007f97 |
38 | sub interpolate_unquoted { |
0c1bedfc |
39 | my $self = shift; |
40 | my ($type, $value) = @_; |
41 | |
7d17f469 |
42 | return $self->next::method(@_) if not defined $value or not defined $type; |
bbdc039b |
43 | |
87b12551 |
44 | if (my ($key) = grep { $type =~ /$_/i } keys %noquote) { |
80007f97 |
45 | return 1 if $noquote{$key}->($value); |
46 | } |
47 | elsif ($self->is_datatype_numeric($type) && $number->($value)) { |
48 | return 1; |
17d750d7 |
49 | } |
7d17f469 |
50 | |
0c1bedfc |
51 | return $self->next::method(@_); |
52 | } |
53 | |
166c6561 |
54 | sub _prep_interpolated_value { |
e06ad5d5 |
55 | my ($self, $type, $value) = @_; |
56 | |
57 | if ($type =~ /money/i && defined $value) { |
0ac07712 |
58 | # change a ^ not followed by \$ to a \$ |
59 | $value =~ s/^ (?! \$) /\$/x; |
e06ad5d5 |
60 | } |
61 | |
62 | return $value; |
63 | } |
64 | |
5608593e |
65 | 1; |
7e8cecc1 |
66 | |
67 | =head1 NAME |
68 | |
057db5ce |
69 | DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for |
70 | Sybase ASE without placeholder support |
7e8cecc1 |
71 | |
72 | =head1 DESCRIPTION |
73 | |
48580715 |
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. |
22b3249c |
76 | |
7e8cecc1 |
77 | You can also enable this driver explicitly using: |
78 | |
79 | my $schema = SchemaClass->clone; |
057db5ce |
80 | $schema->storage_type('::DBI::Sybase::ASE::NoBindVars'); |
7e8cecc1 |
81 | $schema->connect($dsn, $user, $pass, \%opts); |
82 | |
5529838f |
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. |
7e8cecc1 |
87 | |
88 | One advantage of not using placeholders is that C<select @@identity> will work |
48580715 |
89 | for obtaining the last insert id of an C<IDENTITY> column, instead of having to |
e97a6ee2 |
90 | do C<select max(col)> in a transaction as the base Sybase driver does. |
7e8cecc1 |
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 | |
a2bd3796 |
98 | =head1 FURTHER QUESTIONS? |
7e8cecc1 |
99 | |
a2bd3796 |
100 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. |
7e8cecc1 |
101 | |
a2bd3796 |
102 | =head1 COPYRIGHT AND LICENSE |
7e8cecc1 |
103 | |
a2bd3796 |
104 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> |
105 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can |
106 | redistribute it and/or modify it under the same terms as the |
107 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. |