<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars;

use base qw/
  DBIx::Class::Storage::DBI::NoBindVars
  DBIx::Class::Storage::DBI::Sybase::ASE
/;
use mro 'c3';
use List::Util 'first';
use Scalar::Util 'looks_like_number';
use namespace::clean;

sub _init {
  my $self = shift;
  $self-&gt;disable_sth_caching(1);
  $self-&gt;_identity_method('@@IDENTITY');
  $self-&gt;next::method (@_);
}

sub _fetch_identity_sql { 'SELECT ' . $_[0]-&gt;_identity_method }

my $number = sub { looks_like_number $_[0] };

my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x };

my %noquote = (
    int =&gt; sub { $_[0] =~ /^ [-+]? \d+ \z/x },
    bit =&gt; =&gt; sub { $_[0] =~ /^[01]\z/ },
    money =&gt; sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x },
    float =&gt; $number,
    real =&gt; $number,
    double =&gt; $number,
    decimal =&gt; $decimal,
    numeric =&gt; $decimal,
);

sub interpolate_unquoted {
  my $self = shift;
  my ($type, $value) = @_;

  return $self-&gt;next::method(@_) if not defined $value or not defined $type;

  if (my $key = first { $type =~ /$_/i } keys %noquote) {
    return 1 if $noquote{$key}-&gt;($value);
  }
  elsif ($self-&gt;is_datatype_numeric($type) &amp;&amp; $number-&gt;($value)) {
    return 1;
  }

  return $self-&gt;next::method(@_);
}

sub _prep_interpolated_value {
  my ($self, $type, $value) = @_;

  if ($type =~ /money/i &amp;&amp; defined $value) {
    # change a ^ not followed by \$ to a \$
    $value =~ s/^ (?! \$) /\$/x;
  }

  return $value;
}

1;

=head1 NAME

DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars - Storage::DBI subclass for
Sybase ASE without placeholder support

=head1 DESCRIPTION

If you're using this driver then your version of Sybase or the libraries you
use to connect to it do not support placeholders.

You can also enable this driver explicitly using:

  my $schema = SchemaClass-&gt;clone;
  $schema-&gt;storage_type('::DBI::Sybase::ASE::NoBindVars');
  $schema-&gt;connect($dsn, $user, $pass, \%opts);

See the discussion in L&lt;&lt; DBD::Sybase/Using ? Placeholders &amp; bind parameters to
$sth-&gt;execute &gt;&gt; for details on the pros and cons of using placeholders.

One advantage of not using placeholders is that C&lt;select @@identity&gt; will work
for obtaining the last insert id of an C&lt;IDENTITY&gt; column, instead of having to
do C&lt;select max(col)&gt; in a transaction as the base Sybase driver does.

When using this driver, bind variables will be interpolated (properly quoted of
course) into the SQL query itself, without using placeholders.

The caching of prepared statements is also explicitly disabled, as the
interpolation renders it useless.

=head1 AUTHORS

See L&lt;DBIx::Class/CONTRIBUTORS&gt;.

=head1 LICENSE

You may distribute this code under the same terms as Perl itself.

=cut
# vim:sts=2 sw=2:
</pre></body></html>