| 1 | package DBIO::Sybase::Storage::ASE::NoBindVars; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Support for Sybase ASE via DBD::Sybase without placeholders | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use base qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | DBIO::Storage::DBI::NoBindVars | ||||||||||||||||||||||||||||
| 9 | DBIO::Sybase::Storage::ASE | ||||||||||||||||||||||||||||
| 10 | 1 | /; | |||||||||||||||||||||||||||
| 11 | 1 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util 'looks_like_number'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 0 | $self->disable_sth_caching(1); | |||||||||||||||||||||||||||
| 20 | 0 | $self->_identity_method('@@IDENTITY'); | |||||||||||||||||||||||||||
| 21 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method } | ||||||||||||||||||||||||||
|
Subroutine
_fetch_identity_sql: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $number = sub { looks_like_number $_[0] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | my %noquote = ( | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | int => sub { $_[0] =~ /^ [-+]? \d+ \z/x }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | bit => sub { $_[0] =~ /^[01]\z/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | money => sub { $_[0] =~ /^\$ \d+ (?:\.\d*)? \z/x }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | 1 | float => $number, | |||||||||||||||||||||||||||
| 35 | real => $number, | ||||||||||||||||||||||||||||
| 36 | double => $number, | ||||||||||||||||||||||||||||
| 37 | decimal => $decimal, | ||||||||||||||||||||||||||||
| 38 | numeric => $decimal, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub interpolate_unquoted { | ||||||||||||||||||||||||||
|
Subroutine
interpolate_unquoted: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 0 | my ($type, $value) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return $self->next::method(@_) if not defined $value or not defined $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and defined $type
MC/DC0%0/2
defined $value and defined $type
defined $value
defined $type
Truth table0%0/3
A and B
A= defined $valueB= defined $type
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (my ($key) = grep { $type =~ /$_/i } keys %noquote) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return 1 if $noquote{$key}->($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | ▶ | elsif ($self->is_datatype_numeric($type) && $number->($value)) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$self->is_datatype_numeric($type) and &$number($value)
MC/DC0%0/2
$self->is_datatype_numeric($type) and &$number($value)
$self->is_datatype_numeric($type)
&$number($value)
Truth table0%0/3
A and B
A= $self->is_datatype_numeric($type)B= &$number($value)
| |||||||||||||||||||||||||||||
| 52 | 0 | return 1; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return $self->next::method(@_); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub _prep_interpolated_value { | ||||||||||||||||||||||||||
|
Subroutine
_prep_interpolated_value: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $type, $value) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($type =~ /money/i && defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type =~ /money/i and defined $value
MC/DC0%0/2
$type =~ /money/i and defined $value
$type =~ /money/i
defined $value
Truth table0%0/3
A and B
A= $type =~ /money/iB= defined $value
| |||||||||||||||||||||||||||||
| 63 | # change a ^ not followed by \$ to a \$ | ||||||||||||||||||||||||||||
| 64 | 0 | $value =~ s/^ (?! \$) /\$/x; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | return $value; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =pod | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 NAME | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | DBIO::Sybase::Storage::ASE::NoBindVars - Support for Sybase ASE via DBD::Sybase without placeholders | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 VERSION | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | version 0.900001 | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Storage driver for Sybase ASE (Adaptive Server Enterprise) accessed via | ||||||||||||||||||||||||||||
| 90 | L<DBD::Sybase> when your combination of L<DBD::Sybase> and libraries (most | ||||||||||||||||||||||||||||
| 91 | likely FreeTDS) does not support C<?> style placeholders. | ||||||||||||||||||||||||||||
| 92 | L<DBIO::Sybase::Storage::ASE> reblesses the storage into this class | ||||||||||||||||||||||||||||
| 93 | automatically on connect when no placeholder support is detected. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | This driver uses L<DBIO::Storage::DBI::NoBindVars> as a base, so bind variables | ||||||||||||||||||||||||||||
| 96 | are interpolated (properly quoted) into the SQL query itself instead of being | ||||||||||||||||||||||||||||
| 97 | passed as placeholders. Because that renders prepared statement caching | ||||||||||||||||||||||||||||
| 98 | useless, caching is explicitly disabled. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | One advantage of not using placeholders is that C<SELECT @@IDENTITY> works for | ||||||||||||||||||||||||||||
| 101 | obtaining the last insert id of an C<IDENTITY> column, instead of having to do | ||||||||||||||||||||||||||||
| 102 | C<SELECT MAX(col)> in a transaction as the base ASE driver does. This class | ||||||||||||||||||||||||||||
| 103 | sets C<_identity_method> to C<@@IDENTITY> accordingly. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | In all other respects it behaves as L<DBIO::Sybase::Storage::ASE>. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 METHODS | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head2 interpolate_unquoted | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Decides whether a given bind value should be interpolated into the SQL | ||||||||||||||||||||||||||||
| 112 | unquoted, based on its column data type. Recognizes the Sybase numeric and | ||||||||||||||||||||||||||||
| 113 | C<MONEY> types and only skips quoting when the value matches the expected | ||||||||||||||||||||||||||||
| 114 | shape for that type. Falls back to | ||||||||||||||||||||||||||||
| 115 | L<DBIO::Storage::DBI::NoBindVars/interpolate_unquoted> otherwise. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head2 _prep_interpolated_value | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Prepares a value for direct interpolation into the SQL query. For C<MONEY> | ||||||||||||||||||||||||||||
| 120 | types it prefixes a C<$> sign when one is not already present. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =over | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =item * L<DBIO::Sybase::Storage::ASE> - Sybase ASE via L<DBD::Sybase> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item * L<DBIO::Storage::DBI::NoBindVars> - placeholder-less interpolation base | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =back | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||
| 139 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||
| 140 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 143 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||