Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / ASE / NoBindVars.pm
CommitLineData
057db5ce 1package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars;
5608593e 2
4a233f30 3use warnings;
4use strict;
5
5608593e 6use base qw/
7 DBIx::Class::Storage::DBI::NoBindVars
057db5ce 8 DBIx::Class::Storage::DBI::Sybase::ASE
5608593e 9/;
322b7a6b 10use mro 'c3';
6298a324 11use Scalar::Util 'looks_like_number';
12use namespace::clean;
5608593e 13
37b17a93 14sub _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 21sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method }
6b1f5ef7 22
6298a324 23my $number = sub { looks_like_number $_[0] };
0c449973 24
b88bf40a 25my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x };
26
b55e97a7 27my %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 38sub 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 54sub _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 651;
7e8cecc1 66
67=head1 NAME
68
057db5ce 69DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for
70Sybase ASE without placeholder support
7e8cecc1 71
72=head1 DESCRIPTION
73
48580715 74If you're using this driver then your version of Sybase or the libraries you
75use to connect to it do not support placeholders.
22b3249c 76
7e8cecc1 77You 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 83See the discussion in
84L<< DBD::Sybase/Using ? Placeholders & bind parameters to $sth->execute >>
85for details on the pros and cons of using placeholders with this particular
86driver.
7e8cecc1 87
88One advantage of not using placeholders is that C<select @@identity> will work
48580715 89for obtaining the last insert id of an C<IDENTITY> column, instead of having to
e97a6ee2 90do C<select max(col)> in a transaction as the base Sybase driver does.
7e8cecc1 91
92When using this driver, bind variables will be interpolated (properly quoted of
93course) into the SQL query itself, without using placeholders.
94
95The caching of prepared statements is also explicitly disabled, as the
96interpolation renders it useless.
97
a2bd3796 98=head1 FURTHER QUESTIONS?
7e8cecc1 99
a2bd3796 100Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
7e8cecc1 101
a2bd3796 102=head1 COPYRIGHT AND LICENSE
7e8cecc1 103
a2bd3796 104This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
105by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
106redistribute it and/or modify it under the same terms as the
107L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.