1 package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars;
7 DBIx::Class::Storage::DBI::NoBindVars
8 DBIx::Class::Storage::DBI::Sybase::ASE
11 use Scalar::Util 'looks_like_number';
16 $self->disable_sth_caching(1);
17 $self->_identity_method('@@IDENTITY');
18 $self->next::method (@_);
21 sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method }
23 my $number = sub { looks_like_number $_[0] };
25 my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x };
28 int => sub { $_[0] =~ /^ [-+]? \d+ \z/x },
29 bit => => sub { $_[0] =~ /^[01]\z/ },
30 money => sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x },
38 sub interpolate_unquoted {
40 my ($type, $value) = @_;
42 return $self->next::method(@_) if not defined $value or not defined $type;
44 if (my ($key) = grep { $type =~ /$_/i } keys %noquote) {
45 return 1 if $noquote{$key}->($value);
47 elsif ($self->is_datatype_numeric($type) && $number->($value)) {
51 return $self->next::method(@_);
54 sub _prep_interpolated_value {
55 my ($self, $type, $value) = @_;
57 if ($type =~ /money/i && defined $value) {
58 # change a ^ not followed by \$ to a \$
59 $value =~ s/^ (?! \$) /\$/x;
69 DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for
70 Sybase ASE without placeholder support
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.
77 You can also enable this driver explicitly using:
79 my $schema = SchemaClass->clone;
80 $schema->storage_type('::DBI::Sybase::ASE::NoBindVars');
81 $schema->connect($dsn, $user, $pass, \%opts);
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
88 One advantage of not using placeholders is that C<select @@identity> will work
89 for obtaining the last insert id of an C<IDENTITY> column, instead of having to
90 do C<select max(col)> in a transaction as the base Sybase driver does.
92 When using this driver, bind variables will be interpolated (properly quoted of
93 course) into the SQL query itself, without using placeholders.
95 The caching of prepared statements is also explicitly disabled, as the
96 interpolation renders it useless.
98 =head1 FURTHER QUESTIONS?
100 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
102 =head1 COPYRIGHT AND LICENSE
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>.