| 1 | package DBIO::Sybase::Storage::ASE; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Sybase ASE SQL Server support for DBIO | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # The ASE::* trait classes below are standalone (no parent) and override | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # methods that also exist in the deep DBIO::Storage::DBI hierarchy reached | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # via DBIO::Sybase::Storage (e.g. last_insert_id, _execute, _insert_bulk, | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # _exec_txn_begin). They MUST be listed before DBIO::Sybase::Storage so the | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # C3 linearisation places them ahead of DBIO::Storage::DBI; otherwise their | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # overrides are shadowed by core and never run (the trait methods chain into | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # core via next::method). | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use base qw/ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | DBIO::Sybase::Storage::ASE::LOBWriter | ||||||||||||||||||||||||||||||||||||||||||
| 16 | DBIO::Sybase::Storage::ASE::BulkInsert | ||||||||||||||||||||||||||||||||||||||||||
| 17 | DBIO::Sybase::Storage::ASE::IdentityRetrieval | ||||||||||||||||||||||||||||||||||||||||||
| 18 | DBIO::Sybase::Storage::ASE::TxnManager | ||||||||||||||||||||||||||||||||||||||||||
| 19 | DBIO::Sybase::Storage | ||||||||||||||||||||||||||||||||||||||||||
| 20 | DBIO::Storage::DBI::AutoCast | ||||||||||||||||||||||||||||||||||||||||||
| 21 | DBIO::Storage::DBI::IdentityInsert | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | /; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use DBIO::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use Scalar::Util qw/blessed weaken/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use List::Util 'first'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use Sub::Name(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | use Context::Preserve 'preserve_context'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use DBIO::Util 'sigwarn_silencer'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | use version (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | __PACKAGE__->sql_maker_class('DBIO::Sybase::SQLMaker'); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | __PACKAGE__->sql_quote_char ([qw/[ ]/]); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | __PACKAGE__->datetime_parser_type( | |||||||||||||||||||||||||||||||||||||||||
| 38 | 'DBIO::Sybase::Storage::ASE::DateTime::Format' | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | __PACKAGE__->mk_group_accessors('simple' => | |||||||||||||||||||||||||||||||||||||||||
| 42 | qw/_identity _identity_method _blob_log_on_update _parent_storage | ||||||||||||||||||||||||||||||||||||||||||
| 43 | _writer_storage _is_writer_storage | ||||||||||||||||||||||||||||||||||||||||||
| 44 | _bulk_storage _is_bulk_storage _began_bulk_work | ||||||||||||||||||||||||||||||||||||||||||
| 45 | / | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | my @also_proxy_to_extra_storages = qw/ | |||||||||||||||||||||||||||||||||||||||||
| 50 | connect_call_set_auto_cast auto_cast connect_call_blob_setup | ||||||||||||||||||||||||||||||||||||||||||
| 51 | connect_call_datetime_setup | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | disconnect _connect_info _sql_maker _sql_maker_opts disable_sth_caching | ||||||||||||||||||||||||||||||||||||||||||
| 54 | auto_savepoint unsafe cursor_class debug debugobj schema | ||||||||||||||||||||||||||||||||||||||||||
| 55 | /; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub _rebless { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rebless: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $no_bind_vars = __PACKAGE__ . '::NoBindVars'; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($self->_using_freetds) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | carp_once <<'EOF' unless $ENV{DBIO_SYBASE_FREETDS_NOWARN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | You are using FreeTDS with Sybase. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | We will do our best to support this configuration, but please consider this | ||||||||||||||||||||||||||||||||||||||||||
| 69 | support experimental. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | TEXT/IMAGE columns will definitely not work. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | You are encouraged to recompile DBD::Sybase with the Sybase Open Client libraries | ||||||||||||||||||||||||||||||||||||||||||
| 74 | instead. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | See perldoc DBIO::Sybase::Storage::ASE for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | To turn off this warning set the DBIO_SYBASE_FREETDS_NOWARN environment | ||||||||||||||||||||||||||||||||||||||||||
| 79 | variable. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (not $self->_use_typeless_placeholders) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($self->_use_placeholders) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->auto_cast(1); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->ensure_class_loaded($no_bind_vars); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | bless $self, $no_bind_vars; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->_rebless; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | elsif (not $self->_get_dbh->{syb_dynamic_supported}) { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # not necessarily FreeTDS, but no placeholders nevertheless | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->ensure_class_loaded($no_bind_vars); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | bless $self, $no_bind_vars; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->_rebless; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # this is highly unlikely, but we check just in case | ||||||||||||||||||||||||||||||||||||||||||
| 101 | elsif (not $self->_use_typeless_placeholders) { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->auto_cast(1); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if (my $ver = $self->_using_freetds && $self->_using_freetds_version) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_using_freetds && $self->_using_freetds_version
MC/DC0%0/2
$self->_using_freetds && $self->_using_freetds_version
$self->_using_freetds
$self->_using_freetds_version
Truth table66%2/3
A && B
A= $self->_using_freetdsB= $self->_using_freetds_version
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | # Only the historic FreeTDS 0.8x line has the known statement-caching bug; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # parse as a dotted version so 1.x is not coerced to a number (and no | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # "isn't numeric" warning is emitted). | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if (version->parse("v$ver") <= version->parse('v0.82')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | carp_once( | |||||||||||||||||||||||||||||||||||||||||
| 117 | "Buggy FreeTDS version $ver detected, statement caching will not work and " | ||||||||||||||||||||||||||||||||||||||||||
| 118 | . 'will be disabled.' | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $self->disable_sth_caching(1); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | $self->_set_max_connect(256); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # create storage for insert/(update blob) transactions, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # unless this is that storage | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | return if $self->_parent_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | my $writer_storage = (ref $self)->new; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | $writer_storage->_is_writer_storage(1); # just info | |||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | $writer_storage->connect_info($self->connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | $writer_storage->auto_cast($self->auto_cast); | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | weaken ($writer_storage->{_parent_storage} = $self); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | $self->_writer_storage($writer_storage); | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | # create a bulk storage unless connect_info is a coderef | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | return if ref($self->_dbi_connect_info->[0]) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # FreeTDS' blk-library cannot do BCP ("Type '7' not implemented", and BULK | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # INSERT is rejected inside the multi-statement txn DBD::Sybase keeps open). | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # Without a bulk storage the _insert_bulk eligibility check falls back to | ||||||||||||||||||||||||||||||||||||||||||
| 145 | # regular array inserts, which is the only thing that works under FreeTDS. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | return if $self->_using_freetds; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my $bulk_storage = (ref $self)->new; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $bulk_storage->_is_bulk_storage(1); # for special ->disconnect acrobatics | |||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $bulk_storage->connect_info($self->connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # this is why | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $bulk_storage->_dbi_connect_info->[0] .= ';bulkLogin=1'; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | weaken ($bulk_storage->{_parent_storage} = $self); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | $self->_bulk_storage($bulk_storage); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | for my $method (@also_proxy_to_extra_storages) { | |||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 60 | my $replaced = __PACKAGE__->can($method); | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 60 | ▶ | *{$method} = Sub::Name::subname $method => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cursor_class: not called CC=3 SCAR=14.7
Subroutine
disable_sth_caching: called CC=3 SCAR=14.7
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | $self->_writer_storage->$replaced(@_) if $self->_writer_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $self->_bulk_storage->$replaced(@_) if $self->_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return $self->$replaced(@_); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 60 | }; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | # Even though we call $sth->finish for uses off the bulk API, there's still an | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # "active statement" warning on disconnect, which we throw away here. | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # This is due to the bug described in _insert_bulk. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # Currently a noop because 'prepare' is used instead of 'prepare_cached'. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | local $SIG{__WARN__} = sigwarn_silencer(qr/active statement/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | if $self->_is_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # so that next transaction gets a dbh | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $self->_began_bulk_work(0) if $self->_is_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->next::method; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # This is only invoked for FreeTDS drivers by ::Storage::DBI::Sybase::FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub _set_autocommit_stmt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_autocommit_stmt: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my ($self, $on) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | return 'SET CHAINED ' . ($on ? 'OFF' : 'ON'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | # Set up session settings for Sybase databases for the connection. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # Make sure we have CHAINED mode turned on if AutoCommit is off in non-FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # DBD::Sybase (since we don't know how DBD::Sybase was compiled.) If however | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # we're using FreeTDS, CHAINED mode turns on an implicit transaction which we | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # only want when AutoCommit is off. | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub _run_connection_actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_connection_actions: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($self->_is_bulk_storage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | # this should be cleared on every reconnect | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $self->_began_bulk_work(0); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $self->_dbh->{syb_chained_txn} = 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | unless $self->_using_freetds; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub connect_call_blob_setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_call_blob_setup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $dbh = $self->_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $dbh->{syb_binary_images} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | $self->_blob_log_on_update($args{log_on_update}) | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if exists $args{log_on_update}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub _is_lob_column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_lob_column: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ($self, $source, $column) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return $self->_is_lob_type($source->column_info($column)->{data_type}); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub _prep_for_execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prep_for_execute: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my ($self, $op, $ident, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $limit; # extract and use shortcut on limit without offset | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ($op eq 'select' and ! $args->[4] and $limit = $args->[3]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$op eq "select" and not $args->[4] and $limit = $args->[3]
$op eq "select" and not $args->[4]
MC/DC0%0/3
$op eq "select" and not $args->[4] and $limit = $args->[3]
$op eq "select"
not $args->[4]
$limit = $args->[3]
Truth table0%0/4
A and not(B) and C
A= $op eq "select"B= not $args->[4]C= $limit = $args->[3]
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $args = [ @$args ]; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $args->[3] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my ($sql, $bind) = $self->next::method($op, $ident, $args); | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # $limit is already sanitized by now | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $sql = join( "\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | "SET ROWCOUNT $limit", | ||||||||||||||||||||||||||||||||||||||||||
| 249 | $sql, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | "SET ROWCOUNT 0", | ||||||||||||||||||||||||||||||||||||||||||
| 251 | ) if $limit; | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if (my $identity_col = $self->_perform_autoinc_retrieval) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $sql .= "\n" . $self->_fetch_identity_sql($ident, $identity_col) | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return ($sql, $bind); | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # Stolen from SQLT, with some modifications. This is a makeshift | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # solution before a sane type-mapping library is available, thus | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # the 'our' for easy overrides. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | our %TYPE_MAPPING = ( | |||||||||||||||||||||||||||||||||||||||||
| 264 | number => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||
| 265 | money => 'money', | ||||||||||||||||||||||||||||||||||||||||||
| 266 | varchar => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 267 | varchar2 => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 268 | timestamp => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 269 | text => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 270 | real => 'double precision', | ||||||||||||||||||||||||||||||||||||||||||
| 271 | comment => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 272 | bit => 'bit', | ||||||||||||||||||||||||||||||||||||||||||
| 273 | tinyint => 'smallint', | ||||||||||||||||||||||||||||||||||||||||||
| 274 | float => 'double precision', | ||||||||||||||||||||||||||||||||||||||||||
| 275 | serial => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||
| 276 | bigserial => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||
| 277 | boolean => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 278 | long => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub _native_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_native_data_type: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $type = lc $type; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $type =~ s/\s* identity//x; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | return uc($TYPE_MAPPING{$type} || $type); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type} || $type
MC/DC0%0/2
$DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type} || $type
$DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type}
$type
Truth table0%0/3
A || B
A= $DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type}B= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | # handles TEXT/IMAGE and transaction for last_insert_id | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my ($source, $to_insert) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $columns_info = $source->columns_info; | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | my $identity_col = | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | (first { $columns_info->{$_}{is_auto_increment} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | keys %$columns_info ) | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
&first(sub { || ''
MC/DC0%0/1
&first(sub {
$columns_info->{$_}{'is_auto_increment'};
}
, keys %$columns_info) || ''
&first(sub {
$columns_info->{$_}{'is_auto_increment'};
}
, keys %$columns_info)
Truth table0%0/2
A
A= &first(sub {
$columns_info->{$_}{'is_auto_increment'};
}
, keys %$columns_info)
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | || ''; | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | # FIXME - this is duplication from DBI.pm. When refactored towards | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # the LobWriter this can be folded back where it belongs. | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | local $self->{_autoinc_supplied_for_op} = exists $to_insert->{$identity_col} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | ? 1 | ||||||||||||||||||||||||||||||||||||||||||
| 306 | : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 307 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 308 | local $self->{_perform_autoinc_retrieval} = | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | ($identity_col and ! exists $to_insert->{$identity_col}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$identity_col and not exists $to_insert->{$identity_col}
MC/DC0%0/2
$identity_col and not exists $to_insert->{$identity_col}
$identity_col
not exists $to_insert->{$identity_col}
Truth table0%0/3
A and not(B)
A= $identity_colB= not exists $to_insert->{$identity_col}
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | ? $identity_col | ||||||||||||||||||||||||||||||||||||||||||
| 311 | : undef | ||||||||||||||||||||||||||||||||||||||||||
| 312 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # check for empty insert | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # INSERT INTO foo DEFAULT VALUES -- does not work with Sybase | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # try to insert explicit 'DEFAULT's instead (except for identity, timestamp | ||||||||||||||||||||||||||||||||||||||||||
| 317 | # and computed columns) | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if (not %$to_insert) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | for my $col ($source->columns) { | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | next if $col eq $identity_col; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $info = $source->column_info($col); | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | next if ref $info->{default_value} eq 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | || (exists $info->{data_type} && (not defined $info->{data_type})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $info->{"default_value"} eq "SCALAR" or exists $info->{"data_type"} and not defined $info->{"data_type"}
exists $info->{"data_type"} and not defined $info->{"data_type"}
MC/DC0%0/3
ref $info->{"default_value"} eq "SCALAR" or exists $info->{"data_type"} and not defined $info->{"data_type"}
ref $info->{"default_value"} eq "SCALAR"
exists $info->{"data_type"}
not defined $info->{"data_type"}
Truth table0%0/4
A or B and not(C)
A= ref $info->{"default_value"} eq "SCALAR"B= exists $info->{"data_type"}C= not defined $info->{"data_type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | next if $info->{data_type} && $info->{data_type} =~ /^timestamp\z/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$info->{"data_type"} and $info->{"data_type"} =~ /^timestamp\z/i
MC/DC0%0/2
$info->{"data_type"} and $info->{"data_type"} =~ /^timestamp\z/i
$info->{"data_type"}
$info->{"data_type"} =~ /^timestamp\z/i
Truth table0%0/3
A and B
A= $info->{"data_type"}B= $info->{"data_type"} =~ /^timestamp\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $to_insert->{$col} = \'DEFAULT'; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $blob_cols = $self->_remove_blob_cols($source, $to_insert); | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | # do we need the horrific SELECT MAX(COL) hack? | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my $need_dumb_last_insert_id = ( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$self->_perform_autoinc_retrieval && ($self->_identity_method || '') ne '@@IDENTITY'
$self->_identity_method || ''
MC/DC0%0/2
$self->_perform_autoinc_retrieval && ($self->_identity_method || '') ne '@@IDENTITY'
$self->_perform_autoinc_retrieval
$self->_identity_method
Truth table0%0/3
A && B
A= $self->_perform_autoinc_retrievalB= $self->_identity_method
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | $self->_perform_autoinc_retrieval | ||||||||||||||||||||||||||||||||||||||||||
| 338 | && | ||||||||||||||||||||||||||||||||||||||||||
| 339 | ($self->_identity_method||'') ne '@@IDENTITY' | ||||||||||||||||||||||||||||||||||||||||||
| 340 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $next = $self->next::can; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # we are already in a transaction, or there are no blobs | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # and we don't need the PK - just (try to) do it | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if ($self->{transaction_depth} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"transaction_depth"} or not $blob_cols || $need_dumb_last_insert_id
$blob_cols || $need_dumb_last_insert_id
MC/DC0%0/3
$self->{"transaction_depth"} or not $blob_cols || $need_dumb_last_insert_id
$self->{"transaction_depth"}
$blob_cols
$need_dumb_last_insert_id
Truth table0%0/4
A or not(B || C)
A= $self->{"transaction_depth"}B= $blob_colsC= $need_dumb_last_insert_id
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | || (!$blob_cols && !$need_dumb_last_insert_id) | ||||||||||||||||||||||||||||||||||||||||||
| 348 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | return $self->_insert ( | |||||||||||||||||||||||||||||||||||||||||
| 350 | $next, $source, $to_insert, $blob_cols, $identity_col | ||||||||||||||||||||||||||||||||||||||||||
| 351 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | # otherwise use the _writer_storage to do the insert+transaction on another | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # connection | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $guard = $self->_writer_storage->txn_scope_guard; | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $updated_cols = $self->_writer_storage->_insert ( | |||||||||||||||||||||||||||||||||||||||||
| 359 | $next, $source, $to_insert, $blob_cols, $identity_col | ||||||||||||||||||||||||||||||||||||||||||
| 360 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $self->_identity($self->_writer_storage->_identity); | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $guard->commit; | |||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return $updated_cols; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub _insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my ($self, $next, $source, $to_insert, $blob_cols, $identity_col) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $updated_cols = $self->$next ($source, $to_insert); | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my $final_row = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | ($identity_col ? | ||||||||||||||||||||||||||||||||||||||||||
| 376 | ($identity_col => $self->last_insert_id($source, $identity_col)) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 377 | %$to_insert, | ||||||||||||||||||||||||||||||||||||||||||
| 378 | %$updated_cols, | ||||||||||||||||||||||||||||||||||||||||||
| 379 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | $self->_insert_blobs ($source, $blob_cols, $final_row) if $blob_cols; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return $updated_cols; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ($source, $fields, $where, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | # | ||||||||||||||||||||||||||||||||||||||||||
| 391 | # When *updating* identities, ASE requires SET IDENTITY_UPDATE called | ||||||||||||||||||||||||||||||||||||||||||
| 392 | # | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if (my $blob_cols = $self->_remove_blob_cols($source, $fields)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | # If there are any blobs in $where, Sybase will return a descriptive error | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # message. | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # XXX blobs can still be used with a LIKE query, and this should be handled. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | # update+blob update(s) done atomically on separate connection | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $self = $self->_writer_storage; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $guard = $self->txn_scope_guard; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | # First update the blob columns to be updated to '' (taken from $fields, where | ||||||||||||||||||||||||||||||||||||||||||
| 405 | # it is originally put by _remove_blob_cols .) | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my %blobs_to_empty = map { ($_ => delete $fields->{$_}) } keys %$blob_cols; | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | # We can't only update NULL blobs, because blobs cannot be in the WHERE clause. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->next::method($source, \%blobs_to_empty, $where, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # Now update the blobs before the other columns in case the update of other | ||||||||||||||||||||||||||||||||||||||||||
| 412 | # columns makes the search condition invalid. | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $rv = $self->_update_blobs($source, $blob_cols, $where); | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if (keys %$fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | # Now set the identity update flags for the actual update | ||||||||||||||||||||||||||||||||||||||||||
| 418 | local $self->{_autoinc_supplied_for_op} = grep | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | { $_->{is_auto_increment} } | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | values %{ $source->columns_info([ keys %$fields ]) } | |||||||||||||||||||||||||||||||||||||||||
| 421 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my $next = $self->next::can; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $args = \@_; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | return preserve_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $self->$next(@$args); | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | } after => sub { $guard->commit }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $guard->commit; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return $rv; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 435 | # Set the identity update flags for the actual update | ||||||||||||||||||||||||||||||||||||||||||
| 436 | local $self->{_autoinc_supplied_for_op} = grep | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | { $_->{is_auto_increment} } | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | values %{ $source->columns_info([ keys %$fields ]) } | |||||||||||||||||||||||||||||||||||||||||
| 439 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | return $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | sub connect_call_datetime_setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_call_datetime_setup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $dbh = $self->_get_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if ($dbh->can('syb_date_fmt')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | # amazingly, this works with FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $dbh->syb_date_fmt('ISO_strict'); | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | carp_once | |||||||||||||||||||||||||||||||||||||||||
| 456 | 'Your DBD::Sybase is too old to support ' | ||||||||||||||||||||||||||||||||||||||||||
| 457 | .'DBIO::InflateColumn::DateTime, please upgrade!'; | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $dbh->do('SET DATEFORMAT mdy'); | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | package DBIO::Sybase::Storage::ASE::DateTime::Format; | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | ▶ | use base 'DBIO::Storage::DateTimeFormat'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | # No preferred_format_class: DateTime::Format::Sybase expects mdy in both | ||||||||||||||||||||||||||||||||||||||||||
| 469 | # directions, but connect_call_datetime_setup configures ISO_strict output. | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | __PACKAGE__->datetime_parse_pattern('%Y-%m-%dT%H:%M:%S.%3NZ'); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 4 | __PACKAGE__->datetime_format_pattern('%m/%d/%Y %H:%M:%S.%3N'); | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | DBIO::Sybase::Storage::ASE - Sybase ASE SQL Server support for DBIO | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | version 0.900001 | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # Recommended connect_info settings for Sybase ASE: | ||||||||||||||||||||||||||||||||||||||||||
| 492 | on_connect_call => [['datetime_setup'], ['blob_setup', log_on_update => 0]] | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | Storage driver for Sybase ASE (Adaptive Server Enterprise) databases via | ||||||||||||||||||||||||||||||||||||||||||
| 497 | L<DBD::Sybase>. | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | If your Sybase version does not support placeholders, the storage is reblessed | ||||||||||||||||||||||||||||||||||||||||||
| 500 | to C<DBIO::Sybase::Storage::ASE::NoBindVars> automatically. FreeTDS connections | ||||||||||||||||||||||||||||||||||||||||||
| 501 | are supported but TEXT/IMAGE columns will not work; use the native Sybase | ||||||||||||||||||||||||||||||||||||||||||
| 502 | OpenClient libraries for full functionality. | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | Autoincrement retrieval is done via C<SELECT MAX(col)> inside a locked | ||||||||||||||||||||||||||||||||||||||||||
| 505 | transaction, as Sybase ASE provides no single-statement equivalent of | ||||||||||||||||||||||||||||||||||||||||||
| 506 | C<SCOPE_IDENTITY()>. TEXT/IMAGE (blob) columns require a separate write | ||||||||||||||||||||||||||||||||||||||||||
| 507 | operation on a dedicated connection and are handled transparently. | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | Bulk inserts use the L<DBD::Sybase> bulk API when available. | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | =head2 connect_call_blob_setup | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | Used as: | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | on_connect_call => [ [ 'blob_setup', log_on_update => 0 ] ] | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | Does C<< $dbh->{syb_binary_images} = 1; >> to return C<IMAGE> data as raw binary | ||||||||||||||||||||||||||||||||||||||||||
| 520 | instead of as a hex string. | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | Recommended. | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | Also sets the C<log_on_update> value for blob write operations. The default is | ||||||||||||||||||||||||||||||||||||||||||
| 525 | C<1>, but C<0> is better if your database is configured for it. | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | See | ||||||||||||||||||||||||||||||||||||||||||
| 528 | L<DBD::Sybase/Handling IMAGE/TEXT data with syb_ct_get_data()/syb_ct_send_data()>. | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | =head2 connect_call_datetime_setup | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | Used as: | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | on_connect_call => 'datetime_setup' | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | In L<connect_info|DBIO::Storage::DBI/connect_info> to set: | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z | ||||||||||||||||||||||||||||||||||||||||||
| 539 | $dbh->do('set dateformat mdy'); # input fmt: 08/13/1979 18:08:55.080 | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | This works for both C<DATETIME> and C<SMALLDATETIME> columns, note that | ||||||||||||||||||||||||||||||||||||||||||
| 542 | C<SMALLDATETIME> columns only have minute precision. | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | =item * L<DBIO::Sybase> - Sybase schema component | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | =item * L<DBIO::Sybase::Storage> - Sybase storage dispatcher | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | =item * L<DBIO::Sybase::Storage::FreeTDS> - FreeTDS connection layer | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | =item * L<DBIO::Storage::DBI> - Base DBI storage class | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||||||||||||||||
| 565 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||||||||||||||||
| 566 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 569 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | =cut | ||||||||||||||||||||||||||||||||||||||||||