1 package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars;
4 DBIx::Class::Storage::DBI::NoBindVars
5 DBIx::Class::Storage::DBI::Sybase::ASE
8 use List::Util 'first';
9 use Scalar::Util 'looks_like_number';
14 $self->disable_sth_caching(1);
15 $self->_identity_method('@@IDENTITY');
16 $self->next::method (@_);
19 sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method }
21 my $number = sub { looks_like_number $_[0] };
23 my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x };
26 int => sub { $_[0] =~ /^ [-+]? \d+ \z/x },
27 bit => => sub { $_[0] =~ /^[01]\z/ },
28 money => sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x },
36 sub interpolate_unquoted {
38 my ($type, $value) = @_;
40 return $self->next::method(@_) if not defined $value or not defined $type;
42 if (my $key = first { $type =~ /$_/i } keys %noquote) {
43 return 1 if $noquote{$key}->($value);
45 elsif ($self->is_datatype_numeric($type) && $number->($value)) {
49 return $self->next::method(@_);
52 sub _prep_interpolated_value {
53 my ($self, $type, $value) = @_;
55 if ($type =~ /money/i && defined $value) {
56 # change a ^ not followed by \$ to a \$
57 $value =~ s/^ (?! \$) /\$/x;
67 DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for
68 Sybase ASE without placeholder support
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.
75 You can also enable this driver explicitly using:
77 my $schema = SchemaClass->clone;
78 $schema->storage_type('::DBI::Sybase::ASE::NoBindVars');
79 $schema->connect($dsn, $user, $pass, \%opts);
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.
84 One advantage of not using placeholders is that C<select @@identity> will work
85 for obtaining the last insert id of an C<IDENTITY> column, instead of having to
86 do C<select max(col)> in a transaction as the base Sybase driver does.
88 When using this driver, bind variables will be interpolated (properly quoted of
89 course) into the SQL query itself, without using placeholders.
91 The caching of prepared statements is also explicitly disabled, as the
92 interpolation renders it useless.
96 See L<DBIx::Class/CONTRIBUTORS>.
100 You may distribute this code under the same terms as Perl itself.