| 1 | package DBIx::Class::Storage::DBI::Sybase::ASE; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use base qw/ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | DBIx::Class::Storage::DBI::Sybase | ||||||||||||||||||||||||||||||||||||||||||
| 8 | DBIx::Class::Storage::DBI::AutoCast | ||||||||||||||||||||||||||||||||||||||||||
| 9 | DBIx::Class::Storage::DBI::IdentityInsert | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | /; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use DBIx::Class::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Scalar::Util qw/blessed weaken/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Sub::Name(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Data::Dumper::Concise 'Dumper'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Context::Preserve 'preserve_context'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use DBIx::Class::_Util 'sigwarn_silencer'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | __PACKAGE__->sql_limit_dialect ('GenericSubQ'); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | __PACKAGE__->sql_quote_char ([qw/[ ]/]); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | __PACKAGE__->datetime_parser_type( | |||||||||||||||||||||||||||||||||||||||||
| 24 | 'DBIx::Class::Storage::DBI::Sybase::ASE::DateTime::Format' | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | __PACKAGE__->mk_group_accessors('simple' => | |||||||||||||||||||||||||||||||||||||||||
| 28 | qw/_identity _identity_method _blob_log_on_update _parent_storage | ||||||||||||||||||||||||||||||||||||||||||
| 29 | _writer_storage _is_writer_storage | ||||||||||||||||||||||||||||||||||||||||||
| 30 | _bulk_storage _is_bulk_storage _began_bulk_work | ||||||||||||||||||||||||||||||||||||||||||
| 31 | / | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | my @also_proxy_to_extra_storages = qw/ | |||||||||||||||||||||||||||||||||||||||||
| 36 | connect_call_set_auto_cast auto_cast connect_call_blob_setup | ||||||||||||||||||||||||||||||||||||||||||
| 37 | connect_call_datetime_setup | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | disconnect _connect_info _sql_maker _sql_maker_opts disable_sth_caching | ||||||||||||||||||||||||||||||||||||||||||
| 40 | auto_savepoint unsafe cursor_class debug debugobj schema | ||||||||||||||||||||||||||||||||||||||||||
| 41 | /; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | DBIx::Class::Storage::DBI::Sybase::ASE - Sybase ASE SQL Server support for | ||||||||||||||||||||||||||||||||||||||||||
| 46 | DBIx::Class | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | This subclass supports L<DBD::Sybase> for real (non-Microsoft) Sybase databases. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | If your version of Sybase does not support placeholders, then your storage will | ||||||||||||||||||||||||||||||||||||||||||
| 55 | be reblessed to L<DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars>. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | You can also enable that driver explicitly, see the documentation for more | ||||||||||||||||||||||||||||||||||||||||||
| 57 | details. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | With this driver there is unfortunately no way to get the C<last_insert_id> | ||||||||||||||||||||||||||||||||||||||||||
| 60 | without doing a C<SELECT MAX(col)>. This is done safely in a transaction | ||||||||||||||||||||||||||||||||||||||||||
| 61 | (locking the table.) See L</INSERTS WITH PLACEHOLDERS>. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | A recommended L<connect_info|DBIx::Class::Storage::DBI/connect_info> setting: | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | on_connect_call => [['datetime_setup'], ['blob_setup', log_on_update => 0]] | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _rebless { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rebless: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $no_bind_vars = __PACKAGE__ . '::NoBindVars'; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($self->_using_freetds) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | carp_once <<'EOF' unless $ENV{DBIC_SYBASE_FREETDS_NOWARN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | You are using FreeTDS with Sybase. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | We will do our best to support this configuration, but please consider this | ||||||||||||||||||||||||||||||||||||||||||
| 82 | support experimental. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | TEXT/IMAGE columns will definitely not work. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | You are encouraged to recompile DBD::Sybase with the Sybase Open Client libraries | ||||||||||||||||||||||||||||||||||||||||||
| 87 | instead. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | See perldoc DBIx::Class::Storage::DBI::Sybase::ASE for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | To turn off this warning set the DBIC_SYBASE_FREETDS_NOWARN environment | ||||||||||||||||||||||||||||||||||||||||||
| 92 | variable. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (not $self->_use_typeless_placeholders) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($self->_use_placeholders) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->auto_cast(1); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->ensure_class_loaded($no_bind_vars); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | bless $self, $no_bind_vars; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->_rebless; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif (not $self->_get_dbh->{syb_dynamic_supported}) { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # not necessarily FreeTDS, but no placeholders nevertheless | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->ensure_class_loaded($no_bind_vars); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | bless $self, $no_bind_vars; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->_rebless; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # this is highly unlikely, but we check just in case | ||||||||||||||||||||||||||||||||||||||||||
| 114 | elsif (not $self->_use_typeless_placeholders) { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->auto_cast(1); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($self->_using_freetds && (my $ver = $self->_using_freetds_version||999) > 0.82) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$self->_using_freetds and (my $ver = $self->_using_freetds_version || 999) > "0.82"
$self->_using_freetds_version || 999
MC/DC0%0/2
$self->_using_freetds and (my $ver = $self->_using_freetds_version || 999) > "0.82"
$self->_using_freetds
$self->_using_freetds_version
Truth table0%0/3
A and B
A= $self->_using_freetdsB= $self->_using_freetds_version
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | carp_once( | |||||||||||||||||||||||||||||||||||||||||
| 126 | "Buggy FreeTDS version $ver detected, statement caching will not work and " | ||||||||||||||||||||||||||||||||||||||||||
| 127 | . 'will be disabled.' | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->disable_sth_caching(1); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->_set_max_connect(256); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # create storage for insert/(update blob) transactions, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # unless this is that storage | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | return if $self->_parent_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $writer_storage = (ref $self)->new; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $writer_storage->_is_writer_storage(1); # just info | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $writer_storage->connect_info($self->connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $writer_storage->auto_cast($self->auto_cast); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | weaken ($writer_storage->{_parent_storage} = $self); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->_writer_storage($writer_storage); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # create a bulk storage unless connect_info is a coderef | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return if ref($self->_dbi_connect_info->[0]) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $bulk_storage = (ref $self)->new; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $bulk_storage->_is_bulk_storage(1); # for special ->disconnect acrobatics | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $bulk_storage->connect_info($self->connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | # this is why | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $bulk_storage->_dbi_connect_info->[0] .= ';bulkLogin=1'; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | weaken ($bulk_storage->{_parent_storage} = $self); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->_bulk_storage($bulk_storage); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | for my $method (@also_proxy_to_extra_storages) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 45 | my $replaced = __PACKAGE__->can($method); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 45 | ▶ | *{$method} = Sub::Name::subname $method => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sql_maker: not called CC=3 SCAR=15.8
Subroutine
schema: called CC=3 SCAR=15.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $self->_writer_storage->$replaced(@_) if $self->_writer_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $self->_bulk_storage->$replaced(@_) if $self->_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return $self->$replaced(@_); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 45 | }; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | # Even though we call $sth->finish for uses off the bulk API, there's still an | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # "active statement" warning on disconnect, which we throw away here. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # This is due to the bug described in _insert_bulk. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # Currently a noop because 'prepare' is used instead of 'prepare_cached'. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | local $SIG{__WARN__} = sigwarn_silencer(qr/active statement/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | if $self->_is_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # so that next transaction gets a dbh | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $self->_began_bulk_work(0) if $self->_is_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $self->next::method; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # This is only invoked for FreeTDS drivers by ::Storage::DBI::Sybase::FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub _set_autocommit_stmt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_autocommit_stmt: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my ($self, $on) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | return 'SET CHAINED ' . ($on ? 'OFF' : 'ON'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | # Set up session settings for Sybase databases for the connection. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # Make sure we have CHAINED mode turned on if AutoCommit is off in non-FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # DBD::Sybase (since we don't know how DBD::Sybase was compiled.) If however | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # we're using FreeTDS, CHAINED mode turns on an implicit transaction which we | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # only want when AutoCommit is off. | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub _run_connection_actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_connection_actions: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($self->_is_bulk_storage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | # this should be cleared on every reconnect | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $self->_began_bulk_work(0); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $self->_dbh->{syb_chained_txn} = 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | unless $self->_using_freetds; | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | =head2 connect_call_blob_setup | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | Used as: | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | on_connect_call => [ [ 'blob_setup', log_on_update => 0 ] ] | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | Does C<< $dbh->{syb_binary_images} = 1; >> to return C<IMAGE> data as raw binary | ||||||||||||||||||||||||||||||||||||||||||
| 227 | instead of as a hex string. | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | Recommended. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | Also sets the C<log_on_update> value for blob write operations. The default is | ||||||||||||||||||||||||||||||||||||||||||
| 232 | C<1>, but C<0> is better if your database is configured for it. | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | See | ||||||||||||||||||||||||||||||||||||||||||
| 235 | L<DBD::Sybase/Handling IMAGE/TEXT data with syb_ct_get_data()/syb_ct_send_data()>. | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub connect_call_blob_setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_call_blob_setup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $dbh = $self->_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $dbh->{syb_binary_images} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | $self->_blob_log_on_update($args{log_on_update}) | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if exists $args{log_on_update}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub _is_lob_column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_lob_column: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my ($self, $source, $column) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return $self->_is_lob_type($source->column_info($column)->{data_type}); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub _prep_for_execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prep_for_execute: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my ($self, $op, $ident, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # | ||||||||||||||||||||||||||||||||||||||||||
| 259 | ### This is commented out because all tests pass. However I am leaving it | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ### here as it may prove necessary (can't think through all combinations) | ||||||||||||||||||||||||||||||||||||||||||
| 261 | ### BTW it doesn't currently work exactly - need better sensitivity to | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # currently set value | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # | ||||||||||||||||||||||||||||||||||||||||||
| 264 | #my ($op, $ident) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # inherit these from the parent for the duration of _prep_for_execute | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # Don't know how to make a localizing loop with if's, otherwise I would | ||||||||||||||||||||||||||||||||||||||||||
| 268 | #local $self->{_autoinc_supplied_for_op} | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # = $self->_parent_storage->_autoinc_supplied_for_op | ||||||||||||||||||||||||||||||||||||||||||
| 270 | #if ($op eq 'insert' or $op eq 'update') and $self->_parent_storage; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | #local $self->{_perform_autoinc_retrieval} | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # = $self->_parent_storage->_perform_autoinc_retrieval | ||||||||||||||||||||||||||||||||||||||||||
| 273 | #if ($op eq 'insert' or $op eq 'update') and $self->_parent_storage; | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $limit; # extract and use shortcut on limit without offset | |||||||||||||||||||||||||||||||||||||||||
| 276 | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $args = [ @$args ]; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $args->[3] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my ($sql, $bind) = $self->next::method($op, $ident, $args); | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | # $limit is already sanitized by now | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | $sql = join( "\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | "SET ROWCOUNT $limit", | ||||||||||||||||||||||||||||||||||||||||||
| 286 | $sql, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | "SET ROWCOUNT 0", | ||||||||||||||||||||||||||||||||||||||||||
| 288 | ) if $limit; | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if (my $identity_col = $self->_perform_autoinc_retrieval) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $sql .= "\n" . $self->_fetch_identity_sql($ident, $identity_col) | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return ($sql, $bind); | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub _fetch_identity_sql { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_identity_sql: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my ($self, $source, $col) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | return sprintf ("SELECT MAX(%s) FROM %s", | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | map { $self->sql_maker->_quote ($_) } ($col, $source->from) | |||||||||||||||||||||||||||||||||||||||||
| 302 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | # Stolen from SQLT, with some modifications. This is a makeshift | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # solution before a sane type-mapping library is available, thus | ||||||||||||||||||||||||||||||||||||||||||
| 307 | # the 'our' for easy overrides. | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 3 | our %TYPE_MAPPING = ( | |||||||||||||||||||||||||||||||||||||||||
| 309 | number => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||
| 310 | money => 'money', | ||||||||||||||||||||||||||||||||||||||||||
| 311 | varchar => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 312 | varchar2 => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 313 | timestamp => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 314 | text => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 315 | real => 'double precision', | ||||||||||||||||||||||||||||||||||||||||||
| 316 | comment => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 317 | bit => 'bit', | ||||||||||||||||||||||||||||||||||||||||||
| 318 | tinyint => 'smallint', | ||||||||||||||||||||||||||||||||||||||||||
| 319 | float => 'double precision', | ||||||||||||||||||||||||||||||||||||||||||
| 320 | serial => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||
| 321 | bigserial => 'numeric', | ||||||||||||||||||||||||||||||||||||||||||
| 322 | boolean => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 323 | long => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||
| 324 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub _native_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_native_data_type: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $type = lc $type; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $type =~ s/\s* identity//x; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | return uc($TYPE_MAPPING{$type} || $type); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$DBIx::Class::Storage::DBI::Sybase::ASE::TYPE_MAPPING{$type} || $type
MC/DC0%0/2
$DBIx::Class::Storage::DBI::Sybase::ASE::TYPE_MAPPING{$type} || $type
$DBIx::Class::Storage::DBI::Sybase::ASE::TYPE_MAPPING{$type}
$type
Truth table0%0/3
A || B
A= $DBIx::Class::Storage::DBI::Sybase::ASE::TYPE_MAPPING{$type}B= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub _execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my ($rv, $sth, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $self->_identity( ($sth->fetchall_arrayref)->[0][0] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | if $self->_perform_autoinc_retrieval; | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | return wantarray ? ($rv, $sth, @bind) : $rv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub last_insert_id { shift->_identity } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_insert_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | # handles TEXT/IMAGE and transaction for last_insert_id | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my ($source, $to_insert) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $columns_info = $source->columns_info; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | my $identity_col = | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | (first { $columns_info->{$_}{is_auto_increment} } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
do {
$columns_info->{$_}{'is_auto_increment'}
}->first(keys %$columns_info) || ''
MC/DC0%0/1
do {
$columns_info->{$_}{'is_auto_increment'}
}->first(keys %$columns_info) || ''
do {
$columns_info->{$_}{'is_auto_increment'}
}->first(keys %$columns_info)
Truth table0%0/2
A
A= do {
$columns_info->{$_}{'is_auto_increment'}
}->first(keys %$columns_info)
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | keys %$columns_info ) | ||||||||||||||||||||||||||||||||||||||||||
| 358 | || ''; | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | # FIXME - this is duplication from DBI.pm. When refactored towards | ||||||||||||||||||||||||||||||||||||||||||
| 361 | # the LobWriter this can be folded back where it belongs. | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | local $self->{_autoinc_supplied_for_op} = exists $to_insert->{$identity_col} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | ? 1 | ||||||||||||||||||||||||||||||||||||||||||
| 364 | : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 365 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 366 | local $self->{_perform_autoinc_retrieval} = | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 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}
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | ? $identity_col | ||||||||||||||||||||||||||||||||||||||||||
| 369 | : undef | ||||||||||||||||||||||||||||||||||||||||||
| 370 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | # check for empty insert | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # INSERT INTO foo DEFAULT VALUES -- does not work with Sybase | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # try to insert explicit 'DEFAULT's instead (except for identity, timestamp | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # and computed columns) | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if (not %$to_insert) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | for my $col ($source->columns) { | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | next if $col eq $identity_col; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $info = $source->column_info($col); | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | next if ref $info->{default_value} eq 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $to_insert->{$col} = \'DEFAULT'; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my $blob_cols = $self->_remove_blob_cols($source, $to_insert); | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | # do we need the horrific SELECT MAX(COL) hack? | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | $self->_perform_autoinc_retrieval | ||||||||||||||||||||||||||||||||||||||||||
| 396 | && | ||||||||||||||||||||||||||||||||||||||||||
| 397 | ($self->_identity_method||'') ne '@@IDENTITY' | ||||||||||||||||||||||||||||||||||||||||||
| 398 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $next = $self->next::can; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | # we are already in a transaction, or there are no blobs | ||||||||||||||||||||||||||||||||||||||||||
| 403 | # and we don't need the PK - just (try to) do it | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | || (!$blob_cols && !$need_dumb_last_insert_id) | ||||||||||||||||||||||||||||||||||||||||||
| 406 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | return $self->_insert ( | |||||||||||||||||||||||||||||||||||||||||
| 408 | $next, $source, $to_insert, $blob_cols, $identity_col | ||||||||||||||||||||||||||||||||||||||||||
| 409 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | # otherwise use the _writer_storage to do the insert+transaction on another | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # connection | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $guard = $self->_writer_storage->txn_scope_guard; | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $updated_cols = $self->_writer_storage->_insert ( | |||||||||||||||||||||||||||||||||||||||||
| 417 | $next, $source, $to_insert, $blob_cols, $identity_col | ||||||||||||||||||||||||||||||||||||||||||
| 418 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $self->_identity($self->_writer_storage->_identity); | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $guard->commit; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return $updated_cols; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub _insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my ($self, $next, $source, $to_insert, $blob_cols, $identity_col) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | my $updated_cols = $self->$next ($source, $to_insert); | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my $final_row = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | ($identity_col ? | ||||||||||||||||||||||||||||||||||||||||||
| 434 | ($identity_col => $self->last_insert_id($source, $identity_col)) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 435 | %$to_insert, | ||||||||||||||||||||||||||||||||||||||||||
| 436 | %$updated_cols, | ||||||||||||||||||||||||||||||||||||||||||
| 437 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | $self->_insert_blobs ($source, $blob_cols, $final_row) if $blob_cols; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | return $updated_cols; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my ($source, $fields, $where, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | # | ||||||||||||||||||||||||||||||||||||||||||
| 449 | # When *updating* identities, ASE requires SET IDENTITY_UPDATE called | ||||||||||||||||||||||||||||||||||||||||||
| 450 | # | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | if (my $blob_cols = $self->_remove_blob_cols($source, $fields)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | # If there are any blobs in $where, Sybase will return a descriptive error | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # message. | ||||||||||||||||||||||||||||||||||||||||||
| 455 | # XXX blobs can still be used with a LIKE query, and this should be handled. | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | # update+blob update(s) done atomically on separate connection | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $self = $self->_writer_storage; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $guard = $self->txn_scope_guard; | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | # First update the blob columns to be updated to '' (taken from $fields, where | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # it is originally put by _remove_blob_cols .) | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my %blobs_to_empty = map { ($_ => delete $fields->{$_}) } keys %$blob_cols; | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | # We can't only update NULL blobs, because blobs cannot be in the WHERE clause. | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $self->next::method($source, \%blobs_to_empty, $where, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | # Now update the blobs before the other columns in case the update of other | ||||||||||||||||||||||||||||||||||||||||||
| 470 | # columns makes the search condition invalid. | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $rv = $self->_update_blobs($source, $blob_cols, $where); | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if (keys %$fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | # Now set the identity update flags for the actual update | ||||||||||||||||||||||||||||||||||||||||||
| 476 | local $self->{_autoinc_supplied_for_op} = grep | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | { $_->{is_auto_increment} } | |||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | values %{ $source->columns_info([ keys %$fields ]) } | |||||||||||||||||||||||||||||||||||||||||
| 479 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $next = $self->next::can; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my $args = \@_; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | return preserve_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $self->$next(@$args); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | } after => sub { $guard->commit }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $guard->commit; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | return $rv; | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 493 | # Set the identity update flags for the actual update | ||||||||||||||||||||||||||||||||||||||||||
| 494 | local $self->{_autoinc_supplied_for_op} = grep | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | { $_->{is_auto_increment} } | |||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | values %{ $source->columns_info([ keys %$fields ]) } | |||||||||||||||||||||||||||||||||||||||||
| 497 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | return $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | sub _insert_bulk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_bulk: not called CC=15 SCAR=53.2
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my ($source, $cols, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | my $columns_info = $source->columns_info; | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | my ($identity_col) = | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | grep { $columns_info->{$_}{is_auto_increment} } | |||||||||||||||||||||||||||||||||||||||||
| 511 | keys %$columns_info; | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | # FIXME - this is duplication from DBI.pm. When refactored towards | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # the LobWriter this can be folded back where it belongs. | ||||||||||||||||||||||||||||||||||||||||||
| 515 | local $self->{_autoinc_supplied_for_op} | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | = grep { $_ eq $identity_col } @$cols; | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | my $use_bulk_api = | ||||||||||||||||||||||||||||||||||||||||||
| 519 | $self->_bulk_storage && | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | $self->_get_dbh->{syb_has_blk}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_bulk_storage && $self->_get_dbh->{'syb_has_blk'}
MC/DC0%0/2
$self->_bulk_storage && $self->_get_dbh->{'syb_has_blk'}
$self->_bulk_storage
$self->_get_dbh->{'syb_has_blk'}
Truth table0%0/3
A && B
A= $self->_bulk_storageB= $self->_get_dbh->{'syb_has_blk'}
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | if (! $use_bulk_api and ref($self->_dbi_connect_info->[0]) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $use_bulk_api and ref $self->_dbi_connect_info->[0] eq "CODE"
MC/DC0%0/2
not $use_bulk_api and ref $self->_dbi_connect_info->[0] eq "CODE"
not $use_bulk_api
ref $self->_dbi_connect_info->[0] eq "CODE"
Truth table0%0/3
not(A) and B
A= not $use_bulk_apiB= ref $self->_dbi_connect_info->[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | carp_unique( join ' ', | |||||||||||||||||||||||||||||||||||||||||
| 524 | 'Bulk API support disabled due to use of a CODEREF connect_info.', | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 'Reverting to regular array inserts.', | ||||||||||||||||||||||||||||||||||||||||||
| 526 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if (not $use_bulk_api) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $blob_cols = $self->_remove_blob_cols_array($source, $cols, $data); | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | # next::method uses a txn anyway, but it ends too early in case we need to | ||||||||||||||||||||||||||||||||||||||||||
| 533 | # select max(col) to get the identity for inserting blobs. | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | ($self, my $guard) = $self->{transaction_depth} == 0 ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | ($self->_writer_storage, $self->_writer_storage->txn_scope_guard) | ||||||||||||||||||||||||||||||||||||||||||
| 536 | : | ||||||||||||||||||||||||||||||||||||||||||
| 537 | ($self, undef); | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | if ($blob_cols) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | if ($self->_autoinc_supplied_for_op) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $self->_insert_blobs_array ($source, $blob_cols, $cols, $data); | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my @cols_with_identities = (@$cols, $identity_col); | |||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | ## calculate identities | ||||||||||||||||||||||||||||||||||||||||||
| 549 | # XXX This assumes identities always increase by 1, which may or may not | ||||||||||||||||||||||||||||||||||||||||||
| 550 | # be true. | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | my ($last_identity) = | |||||||||||||||||||||||||||||||||||||||||
| 552 | $self->_dbh->selectrow_array ( | ||||||||||||||||||||||||||||||||||||||||||
| 553 | $self->_fetch_identity_sql($source, $identity_col) | ||||||||||||||||||||||||||||||||||||||||||
| 554 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my @identities = (($last_identity - @$data + 1) .. $last_identity); | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | my @data_with_identities = map [@$_, shift @identities], @$data; | |||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | $self->_insert_blobs_array ( | |||||||||||||||||||||||||||||||||||||||||
| 560 | $source, $blob_cols, \@cols_with_identities, \@data_with_identities | ||||||||||||||||||||||||||||||||||||||||||
| 561 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | $guard->commit if $guard; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | # otherwise, use the bulk API | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | # rearrange @$data so that columns are in database order | ||||||||||||||||||||||||||||||||||||||||||
| 573 | # and so we submit a full column list | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my %orig_order = map { $cols->[$_] => $_ } 0..$#$cols; | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | my @source_columns = $source->columns; | |||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | # bcp identity index is 1-based | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my ($identity_idx) = grep { $source_columns[$_] eq $identity_col } (0..$#source_columns); | |||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | $identity_idx = defined $identity_idx ? $identity_idx + 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my @new_data; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | for my $slice_idx (0..$#$data) { | |||||||||||||||||||||||||||||||||||||||||
| 584 | push @new_data, [map { | ||||||||||||||||||||||||||||||||||||||||||
| 585 | # identity data will be 'undef' if not _autoinc_supplied_for_op() | ||||||||||||||||||||||||||||||||||||||||||
| 586 | # columns with defaults will also be 'undef' | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | exists $orig_order{$_} | |||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | ? $data->[$slice_idx][$orig_order{$_}] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | : undef | ||||||||||||||||||||||||||||||||||||||||||
| 590 | } @source_columns]; | ||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | my $proto_bind = $self->_resolve_bindattrs( | ||||||||||||||||||||||||||||||||||||||||||
| 594 | $source, | ||||||||||||||||||||||||||||||||||||||||||
| 595 | [map { | ||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | [ { dbic_colname => $source_columns[$_], _bind_data_slice_idx => $_ } | |||||||||||||||||||||||||||||||||||||||||
| 597 | => $new_data[0][$_] ] | ||||||||||||||||||||||||||||||||||||||||||
| 598 | } (0 ..$#source_columns) ], | ||||||||||||||||||||||||||||||||||||||||||
| 599 | $columns_info | ||||||||||||||||||||||||||||||||||||||||||
| 600 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | ## Set a client-side conversion error handler, straight from DBD::Sybase docs. | ||||||||||||||||||||||||||||||||||||||||||
| 603 | # This ignores any data conversion errors detected by the client side libs, as | ||||||||||||||||||||||||||||||||||||||||||
| 604 | # they are usually harmless. | ||||||||||||||||||||||||||||||||||||||||||
| 605 | my $orig_cslib_cb = DBD::Sybase::set_cslib_cb( | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | Sub::Name::subname _insert_bulk_cslib_errhandler => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my ($layer, $origin, $severity, $errno, $errmsg, $osmsg, $blkmsg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | return 1 if $errno == 36; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | carp | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | "Layer: $layer, Origin: $origin, Severity: $severity, Error: $errno" . | ||||||||||||||||||||||||||||||||||||||||||
| 613 | ($errmsg ? "\n$errmsg" : '') . | ||||||||||||||||||||||||||||||||||||||||||
| 614 | ($osmsg ? "\n$osmsg" : '') . | ||||||||||||||||||||||||||||||||||||||||||
| 615 | ($blkmsg ? "\n$blkmsg" : ''); | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my $exception = ''; | |||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | my $bulk = $self->_bulk_storage; | |||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | my $guard = $bulk->txn_scope_guard; | |||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | ## FIXME - once this is done - address the FIXME on finish() below | ||||||||||||||||||||||||||||||||||||||||||
| 627 | ## XXX get this to work instead of our own $sth | ||||||||||||||||||||||||||||||||||||||||||
| 628 | ## will require SQLMaker or *Hacks changes for ordered columns | ||||||||||||||||||||||||||||||||||||||||||
| 629 | # $bulk->next::method($source, \@source_columns, \@new_data, { | ||||||||||||||||||||||||||||||||||||||||||
| 630 | # syb_bcp_attribs => { | ||||||||||||||||||||||||||||||||||||||||||
| 631 | # identity_flag => $self->_autoinc_supplied_for_op ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 632 | # identity_column => $identity_idx, | ||||||||||||||||||||||||||||||||||||||||||
| 633 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | # }); | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | my $sql = 'INSERT INTO ' . | |||||||||||||||||||||||||||||||||||||||||
| 636 | $bulk->sql_maker->_quote($source->name) . ' (' . | ||||||||||||||||||||||||||||||||||||||||||
| 637 | # colname list is ignored for BCP, but does no harm | ||||||||||||||||||||||||||||||||||||||||||
| 638 | (join ', ', map $bulk->sql_maker->_quote($_), @source_columns) . ') '. | ||||||||||||||||||||||||||||||||||||||||||
| 639 | ' VALUES ('. (join ', ', ('?') x @source_columns) . ')'; | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | ## XXX there's a bug in the DBD::Sybase bulk support that makes $sth->finish for | ||||||||||||||||||||||||||||||||||||||||||
| 642 | ## a prepare_cached statement ineffective. Replace with ->sth when fixed, or | ||||||||||||||||||||||||||||||||||||||||||
| 643 | ## better yet the version above. Should be fixed in DBD::Sybase . | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | my $sth = $bulk->_get_dbh->prepare($sql, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | # 'insert', # op | ||||||||||||||||||||||||||||||||||||||||||
| 646 | { | ||||||||||||||||||||||||||||||||||||||||||
| 647 | syb_bcp_attribs => { | ||||||||||||||||||||||||||||||||||||||||||
| 648 | identity_flag => $self->_autoinc_supplied_for_op ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 649 | identity_column => $identity_idx, | ||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | { | ||||||||||||||||||||||||||||||||||||||||||
| 655 | # FIXME the $sth->finish in _execute_array does a rollback for some | ||||||||||||||||||||||||||||||||||||||||||
| 656 | # reason. Disable it temporarily until we fix the SQLMaker thing above | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | local *{ref($sth).'::finish'} = sub {}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | $self->_dbh_execute_for_fetch( | |||||||||||||||||||||||||||||||||||||||||
| 662 | $source, $sth, $proto_bind, \@source_columns, \@new_data | ||||||||||||||||||||||||||||||||||||||||||
| 663 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $guard->commit; | |||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | $bulk->_query_end($sql); | |||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | $exception = shift; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | DBD::Sybase::set_cslib_cb($orig_cslib_cb); | |||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | ▶ | if ($exception =~ /-Y option/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | my $w = 'Sybase bulk API operation failed due to character set incompatibility, ' | |||||||||||||||||||||||||||||||||||||||||
| 677 | . 'reverting to regular array inserts. Try unsetting the LANG environment variable' | ||||||||||||||||||||||||||||||||||||||||||
| 678 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | $w .= "\n$exception" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | carp $w; | |||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $self->_bulk_storage(undef); | |||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | unshift @_, $self; | |||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | goto \&_insert_bulk; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | elsif ($exception) { | ||||||||||||||||||||||||||||||||||||||||||
| 687 | # rollback makes the bulkLogin connection unusable | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | $self->_bulk_storage->disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $self->throw_exception($exception); | |||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | # Make sure blobs are not bound as placeholders, and return any non-empty ones | ||||||||||||||||||||||||||||||||||||||||||
| 694 | # as a hash. | ||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | sub _remove_blob_cols { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_blob_cols: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | my ($self, $source, $fields) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my %blob_cols; | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | for my $col (keys %$fields) { | |||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | if ($self->_is_lob_column($source, $col)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my $blob_val = delete $fields->{$col}; | |||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | if (not defined $blob_val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | $fields->{$col} = \'NULL'; | |||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $fields->{$col} = \"''"; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | $blob_cols{$col} = $blob_val unless $blob_val eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | return %blob_cols ? \%blob_cols : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | # same for _insert_bulk | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | sub _remove_blob_cols_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_blob_cols_array: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my ($self, $source, $cols, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my @blob_cols; | |||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | for my $i (0..$#$cols) { | |||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my $col = $cols->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | ▶ | if ($self->_is_lob_column($source, $col)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | for my $j (0..$#$data) { | |||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | my $blob_val = delete $data->[$j][$i]; | |||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | if (not defined $blob_val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | $data->[$j][$i] = \'NULL'; | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | $data->[$j][$i] = \"''"; | |||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | ▶ | $blob_cols[$j][$i] = $blob_val | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | unless $blob_val eq ''; | ||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | return @blob_cols ? \@blob_cols : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | sub _update_blobs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_blobs: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my ($self, $source, $blob_cols, $where) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | my @primary_cols = try | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | { $source->_pri_cols_or_die } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $self->throw_exception("Cannot update TEXT/IMAGE column(s): $_") | |||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | my @pks_to_update; | |||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $where eq "HASH" and @primary_cols == grep({defined $where->{$_};} @primary_cols)
MC/DC0%0/2
ref $where eq "HASH" and @primary_cols == grep({defined $where->{$_};} @primary_cols)
ref $where eq "HASH"
@primary_cols == grep({defined $where->{$_};} @primary_cols)
Truth table0%0/3
A and B
A= ref $where eq "HASH"B= @primary_cols == grep({defined $where->{$_};} @primary_cols)
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | ref $where eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 755 | and | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | @primary_cols == grep { defined $where->{$_} } @primary_cols | |||||||||||||||||||||||||||||||||||||||||
| 757 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | my %row_to_update; | |||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | @row_to_update{@primary_cols} = @{$where}{@primary_cols}; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | @pks_to_update = \%row_to_update; | |||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | my $cursor = $self->select ($source, \@primary_cols, $where, {}); | |||||||||||||||||||||||||||||||||||||||||
| 764 | @pks_to_update = map { | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | my %row; @row{@primary_cols} = @$_; \%row | |||||||||||||||||||||||||||||||||||||||||
| 766 | } $cursor->all; | ||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | for my $ident (@pks_to_update) { | |||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $self->_insert_blobs($source, $blob_cols, $ident); | |||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | sub _insert_blobs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_blobs: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | my ($self, $source, $blob_cols, $row) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my $dbh = $self->_get_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | my $table = $source->name; | |||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | my %row = %$row; | |||||||||||||||||||||||||||||||||||||||||
| 781 | my @primary_cols = try | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | { $source->_pri_cols_or_die } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $self->throw_exception("Cannot update TEXT/IMAGE column(s): $_") | |||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | $self->throw_exception('Cannot update TEXT/IMAGE column(s) without primary key values') | ||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | if ((grep { defined $row{$_} } @primary_cols) != @primary_cols); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | # if we are 2-phase inserting a blob - there is nothing to retrieve anymore, | ||||||||||||||||||||||||||||||||||||||||||
| 791 | # regardless of the previous state of the flag | ||||||||||||||||||||||||||||||||||||||||||
| 792 | local $self->{_perform_autoinc_retrieval} | ||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | ▶ | if $self->_perform_autoinc_retrieval; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | for my $col (keys %$blob_cols) { | |||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | my $blob = $blob_cols->{$col}; | |||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | my %where = map { ($_, $row{$_}) } @primary_cols; | |||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | my $cursor = $self->select ($source, [$col], \%where, {}); | |||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | $cursor->next; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | my $sth = $cursor->sth; | |||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | if (not $sth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | $self->throw_exception( | |||||||||||||||||||||||||||||||||||||||||
| 806 | "Could not find row in table '$table' for blob update:\n" | ||||||||||||||||||||||||||||||||||||||||||
| 807 | . (Dumper \%where) | ||||||||||||||||||||||||||||||||||||||||||
| 808 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | $sth->func('CS_GET', 1, 'ct_data_info') or die $sth->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | } while $sth->fetch; | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | $sth->func('ct_prepare_send') or die $sth->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $log_on_update = $self->_blob_log_on_update; | |||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | $log_on_update = 1 if not defined $log_on_update; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | $sth->func('CS_SET', 1, { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | total_txtlen => length($blob), | ||||||||||||||||||||||||||||||||||||||||||
| 823 | log_on_update => $log_on_update | ||||||||||||||||||||||||||||||||||||||||||
| 824 | }, 'ct_data_info') or die $sth->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | $sth->func($blob, length($blob), 'ct_send_data') or die $sth->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | $sth->func('ct_finish_send') or die $sth->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | ▶ | if ($self->_using_freetds) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | $self->throw_exception ( | |||||||||||||||||||||||||||||||||||||||||
| 833 | "TEXT/IMAGE operation failed, probably because you are using FreeTDS: $_" | ||||||||||||||||||||||||||||||||||||||||||
| 834 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||
| 836 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | $self->throw_exception($_); | |||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | ▶ | finally { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | ▶ | $sth->finish if $sth; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | ▶ | sub _insert_blobs_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_blobs_array: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | my ($self, $source, $blob_cols, $cols, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | for my $i (0..$#$data) { | |||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | my $datum = $data->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | my %row; | |||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | @row{ @$cols } = @$datum; | |||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | my %blob_vals; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | for my $j (0..$#$cols) { | |||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | ▶ | if (exists $blob_cols->[$i][$j]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | $blob_vals{ $cols->[$j] } = $blob_cols->[$i][$j]; | |||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | $self->_insert_blobs ($source, \%blob_vals, \%row); | |||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | =head2 connect_call_datetime_setup | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | Used as: | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | on_connect_call => 'datetime_setup' | ||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set: | ||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z | ||||||||||||||||||||||||||||||||||||||||||
| 875 | $dbh->do('set dateformat mdy'); # input fmt: 08/13/1979 18:08:55.080 | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | This works for both C<DATETIME> and C<SMALLDATETIME> columns, note that | ||||||||||||||||||||||||||||||||||||||||||
| 878 | C<SMALLDATETIME> columns only have minute precision. | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | ▶ | sub connect_call_datetime_setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_call_datetime_setup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | my $dbh = $self->_get_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | ▶ | if ($dbh->can('syb_date_fmt')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 887 | # amazingly, this works with FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | $dbh->syb_date_fmt('ISO_strict'); | |||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||
| 890 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | carp_once | |||||||||||||||||||||||||||||||||||||||||
| 892 | 'Your DBD::Sybase is too old to support ' | ||||||||||||||||||||||||||||||||||||||||||
| 893 | .'DBIx::Class::InflateColumn::DateTime, please upgrade!'; | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | # FIXME - in retrospect this is a rather bad US-centric choice | ||||||||||||||||||||||||||||||||||||||||||
| 896 | # of format. Not changing as a bugwards compat, though in reality | ||||||||||||||||||||||||||||||||||||||||||
| 897 | # the only piece that sees the results of $dt object formatting | ||||||||||||||||||||||||||||||||||||||||||
| 898 | # (as opposed to parsing) is the database itself, so theoretically | ||||||||||||||||||||||||||||||||||||||||||
| 899 | # changing both this SET command and the formatter definition of | ||||||||||||||||||||||||||||||||||||||||||
| 900 | # ::S::D::Sybase::ASE::DateTime::Format below should be safe and | ||||||||||||||||||||||||||||||||||||||||||
| 901 | # transparent | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | $dbh->do('SET DATEFORMAT mdy'); | |||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | ▶ | sub _exec_txn_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_txn_begin: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | # bulkLogin=1 connections are always in a transaction, and can only call BEGIN | ||||||||||||||||||||||||||||||||||||||||||
| 912 | # TRAN once. However, we need to make sure there's a $dbh. | ||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | ▶ | return if $self->_is_bulk_storage && $self->_dbh && $self->_began_bulk_work; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->_is_bulk_storage and $self->_dbh and $self->_began_bulk_work
$self->_is_bulk_storage and $self->_dbh
MC/DC0%0/3
$self->_is_bulk_storage and $self->_dbh and $self->_began_bulk_work
$self->_is_bulk_storage
$self->_dbh
$self->_began_bulk_work
Truth table0%0/4
A and B and C
A= $self->_is_bulk_storageB= $self->_dbhC= $self->_began_bulk_work
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | ▶ | $self->_began_bulk_work(1) if $self->_is_bulk_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | # savepoint support using ASE syntax | ||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | sub _exec_svp_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_svp_begin: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | $self->_dbh->do("SAVE TRANSACTION $name"); | |||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | # A new SAVE TRANSACTION with the same name releases the previous one. | ||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | sub _exec_svp_release { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_svp_release: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | ▶ | sub _exec_svp_rollback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_svp_rollback: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | $self->_dbh->do("ROLLBACK TRANSACTION $name"); | |||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||
| 938 | DBIx::Class::Storage::DBI::Sybase::ASE::DateTime::Format; | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 3 | my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ'; | |||||||||||||||||||||||||||||||||||||||||
| 941 | 3 | my $datetime_format_format = '%m/%d/%Y %H:%M:%S.%3N'; | |||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | 3 | my ($datetime_parser, $datetime_formatter); | |||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | ▶ | sub parse_datetime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_datetime: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | require DateTime::Format::Strptime; | |||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | $datetime_parser ||= DateTime::Format::Strptime->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$datetime_parser ||= "DateTime::Format::Strptime"->new("pattern", $datetime_parse_format, "on_error", "croak")
MC/DC0%0/2
$datetime_parser ||= "DateTime::Format::Strptime"->new("pattern", $datetime_parse_format, "on_error", "croak")
$datetime_parser
"DateTime::Format::Strptime"->new("pattern", $datetime_parse_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $datetime_parserB= "DateTime::Format::Strptime"->new("pattern", $datetime_parse_format, "on_error", "croak")
| |||||||||||||||||||||||||||||||||||||||||||
| 949 | pattern => $datetime_parse_format, | ||||||||||||||||||||||||||||||||||||||||||
| 950 | on_error => 'croak', | ||||||||||||||||||||||||||||||||||||||||||
| 951 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | return $datetime_parser->parse_datetime(shift); | |||||||||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | ▶ | sub format_datetime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_datetime: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | require DateTime::Format::Strptime; | |||||||||||||||||||||||||||||||||||||||||
| 958 | 0 | ▶ | $datetime_formatter ||= DateTime::Format::Strptime->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$datetime_formatter ||= "DateTime::Format::Strptime"->new("pattern", $datetime_format_format, "on_error", "croak")
MC/DC0%0/2
$datetime_formatter ||= "DateTime::Format::Strptime"->new("pattern", $datetime_format_format, "on_error", "croak")
$datetime_formatter
"DateTime::Format::Strptime"->new("pattern", $datetime_format_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $datetime_formatterB= "DateTime::Format::Strptime"->new("pattern", $datetime_format_format, "on_error", "croak")
| |||||||||||||||||||||||||||||||||||||||||||
| 959 | pattern => $datetime_format_format, | ||||||||||||||||||||||||||||||||||||||||||
| 960 | on_error => 'croak', | ||||||||||||||||||||||||||||||||||||||||||
| 961 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | return $datetime_formatter->format_datetime(shift); | |||||||||||||||||||||||||||||||||||||||||
| 963 | } | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | =head1 Schema::Loader Support | ||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||
| 969 | As of version C<0.05000>, L<DBIx::Class::Schema::Loader> should work well with | ||||||||||||||||||||||||||||||||||||||||||
| 970 | most versions of Sybase ASE. | ||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | =head1 FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||
| 974 | This driver supports L<DBD::Sybase> compiled against FreeTDS | ||||||||||||||||||||||||||||||||||||||||||
| 975 | (L<http://www.freetds.org/>) to the best of our ability, however it is | ||||||||||||||||||||||||||||||||||||||||||
| 976 | recommended that you recompile L<DBD::Sybase> against the Sybase Open Client | ||||||||||||||||||||||||||||||||||||||||||
| 977 | libraries. They are a part of the Sybase ASE distribution: | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | The Open Client FAQ is here: | ||||||||||||||||||||||||||||||||||||||||||
| 980 | L<http://www.isug.com/Sybase_FAQ/ASE/section7.html>. | ||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||
| 982 | Sybase ASE for Linux (which comes with the Open Client libraries) may be | ||||||||||||||||||||||||||||||||||||||||||
| 983 | downloaded here: L<http://response.sybase.com/forms/ASE_Linux_Download>. | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | To see if you're using FreeTDS run: | ||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | perl -MDBI -le 'my $dbh = DBI->connect($dsn, $user, $pass); print $dbh->{syb_oc_version}' | ||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||
| 989 | It is recommended to set C<tds version> for your ASE server to C<5.0> in | ||||||||||||||||||||||||||||||||||||||||||
| 990 | C</etc/freetds/freetds.conf>. | ||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||
| 992 | Some versions or configurations of the libraries involved will not support | ||||||||||||||||||||||||||||||||||||||||||
| 993 | placeholders, in which case the storage will be reblessed to | ||||||||||||||||||||||||||||||||||||||||||
| 994 | L<DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars>. | ||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | In some configurations, placeholders will work but will throw implicit type | ||||||||||||||||||||||||||||||||||||||||||
| 997 | conversion errors for anything that's not expecting a string. In such a case, | ||||||||||||||||||||||||||||||||||||||||||
| 998 | the C<auto_cast> option from L<DBIx::Class::Storage::DBI::AutoCast> is | ||||||||||||||||||||||||||||||||||||||||||
| 999 | automatically set, which you may enable on connection with | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | L<connect_call_set_auto_cast|DBIx::Class::Storage::DBI::AutoCast/connect_call_set_auto_cast>. | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | The type info for the C<CAST>s is taken from the | ||||||||||||||||||||||||||||||||||||||||||
| 1002 | L<DBIx::Class::ResultSource/data_type> definitions in your Result classes, and | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | are mapped to a Sybase type (if it isn't already) using a mapping based on | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | L<SQL::Translator>. | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | In other configurations, placeholders will work just as they do with the Sybase | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | Open Client libraries. | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||
| 1009 | Inserts or updates of TEXT/IMAGE columns will B<NOT> work with FreeTDS. | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||
| 1011 | =head1 INSERTS WITH PLACEHOLDERS | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | With placeholders enabled, inserts are done in a transaction so that there are | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | no concurrency issues with getting the inserted identity value using | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | C<SELECT MAX(col)>, which is the only way to get the C<IDENTITY> value in this | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | mode. | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||
| 1018 | In addition, they are done on a separate connection so that it's possible to | ||||||||||||||||||||||||||||||||||||||||||
| 1019 | have active cursors when doing an insert. | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||
| 1021 | When using C<DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars> transactions | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | are unnecessary and not used, as there are no concurrency issues with C<SELECT | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | @@IDENTITY> which is a session variable. | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||
| 1025 | =head1 TRANSACTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||
| 1027 | Due to limitations of the TDS protocol and L<DBD::Sybase>, you cannot begin a | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | transaction while there are active cursors, nor can you use multiple active | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | cursors within a transaction. An active cursor is, for example, a | ||||||||||||||||||||||||||||||||||||||||||
| 1030 | L<ResultSet|DBIx::Class::ResultSet> that has been executed using C<next> or | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | C<first> but has not been exhausted or L<reset|DBIx::Class::ResultSet/reset>. | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||
| 1033 | For example, this will not work: | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||
| 1035 | $schema->txn_do(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 1036 | my $rs = $schema->resultset('Book'); | ||||||||||||||||||||||||||||||||||||||||||
| 1037 | while (my $result = $rs->next) { | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | $schema->resultset('MetaData')->create({ | ||||||||||||||||||||||||||||||||||||||||||
| 1039 | book_id => $result->id, | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1042 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||
| 1045 | This won't either: | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||
| 1047 | my $first_row = $large_rs->first; | ||||||||||||||||||||||||||||||||||||||||||
| 1048 | $schema->txn_do(sub { ... }); | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||
| 1050 | Transactions done for inserts in C<AutoCommit> mode when placeholders are in use | ||||||||||||||||||||||||||||||||||||||||||
| 1051 | are not affected, as they are done on an extra database handle. | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | Some workarounds: | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||
| 1055 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | =item * use L<DBIx::Class::Storage::DBI::Replicated> | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||
| 1059 | =item * L<connect|DBIx::Class::Schema/connect> another L<Schema|DBIx::Class::Schema> | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||
| 1061 | =item * load the data from your cursor with L<DBIx::Class::ResultSet/all> | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||
| 1063 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||
| 1065 | =head1 MAXIMUM CONNECTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||
| 1067 | The TDS protocol makes separate connections to the server for active statements | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | in the background. By default the number of such connections is limited to 25, | ||||||||||||||||||||||||||||||||||||||||||
| 1069 | on both the client side and the server side. | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||
| 1071 | This is a bit too low for a complex L<DBIx::Class> application, so on connection | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | the client side setting is set to C<256> (see L<DBD::Sybase/maxConnect>.) You | ||||||||||||||||||||||||||||||||||||||||||
| 1073 | can override it to whatever setting you like in the DSN. | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||
| 1075 | See | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | L<http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.sag1/html/sag1/sag1272.htm> | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | for information on changing the setting on the server side. | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||
| 1079 | =head1 DATES | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||
| 1081 | See L</connect_call_datetime_setup> to setup date formats | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | for L<DBIx::Class::InflateColumn::DateTime>. | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||
| 1084 | =head1 LIMITED QUERIES | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||
| 1086 | Because ASE does not have a good way to limit results in SQL that works for | ||||||||||||||||||||||||||||||||||||||||||
| 1087 | all types of queries, the limit dialect is set to | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | L<GenericSubQ|DBIx::Class::SQLMaker::LimitDialects/GenericSubQ>. | ||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||
| 1090 | Fortunately, ASE and L<DBD::Sybase> support cursors properly, so when | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | L<GenericSubQ|DBIx::Class::SQLMaker::LimitDialects/GenericSubQ> is too slow | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | you can use the L<software_limit|DBIx::Class::ResultSet/software_limit> | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | L<DBIx::Class::ResultSet> attribute to simulate limited queries by skipping | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | over records. | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||
| 1096 | =head1 TEXT/IMAGE COLUMNS | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||
| 1098 | L<DBD::Sybase> compiled with FreeTDS will B<NOT> allow you to insert or update | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | C<TEXT/IMAGE> columns. | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||
| 1101 | Setting C<< $dbh->{LongReadLen} >> will also not work with FreeTDS use either: | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||
| 1103 | $schema->storage->dbh->do("SET TEXTSIZE $bytes"); | ||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||
| 1105 | or | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||
| 1107 | $schema->storage->set_textsize($bytes); | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||
| 1109 | instead. | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||
| 1111 | However, the C<LongReadLen> you pass in | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | L<connect_info|DBIx::Class::Storage::DBI/connect_info> is used to execute the | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | equivalent C<SET TEXTSIZE> command on connection. | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||
| 1115 | See L</connect_call_blob_setup> for a | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | L<connect_info|DBIx::Class::Storage::DBI/connect_info> setting you need to work | ||||||||||||||||||||||||||||||||||||||||||
| 1117 | with C<IMAGE> columns. | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||
| 1119 | =head1 BULK API | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||
| 1121 | The experimental L<DBD::Sybase> Bulk API support is used for | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | L<populate|DBIx::Class::ResultSet/populate> in B<void> context, in a transaction | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | on a separate connection. | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||
| 1125 | To use this feature effectively, use a large number of rows for each | ||||||||||||||||||||||||||||||||||||||||||
| 1126 | L<populate|DBIx::Class::ResultSet/populate> call, eg.: | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||
| 1128 | while (my $rows = $data_source->get_100_rows()) { | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | $rs->populate($rows); | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||
| 1132 | B<NOTE:> the L<add_columns|DBIx::Class::ResultSource/add_columns> | ||||||||||||||||||||||||||||||||||||||||||
| 1133 | calls in your C<Result> classes B<must> list columns in database order for this | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | to work. Also, you may have to unset the C<LANG> environment variable before | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | loading your app, as C<BCP -Y> is not yet supported in DBD::Sybase . | ||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||
| 1137 | When inserting IMAGE columns using this method, you'll need to use | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | L</connect_call_blob_setup> as well. | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||
| 1140 | =head1 COMPUTED COLUMNS | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||
| 1142 | If you have columns such as: | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | created_dtm AS getdate() | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||
| 1146 | represent them in your Result classes as: | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||
| 1148 | created_dtm => { | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | data_type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | default_value => \'getdate()', | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | is_nullable => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 1152 | inflate_datetime => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||
| 1155 | The C<data_type> must exist and must be C<undef>. Then empty inserts will work | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | on tables with such columns. | ||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||
| 1158 | =head1 TIMESTAMP COLUMNS | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||
| 1160 | C<timestamp> columns in Sybase ASE are not really timestamps, see: | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | L<http://dba.fyicenter.com/Interview-Questions/SYBASE/The_timestamp_datatype_in_Sybase_.html>. | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||
| 1163 | They should be defined in your Result classes as: | ||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||
| 1165 | ts => { | ||||||||||||||||||||||||||||||||||||||||||
| 1166 | data_type => 'timestamp', | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | is_nullable => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | inflate_datetime => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||
| 1171 | The C<<inflate_datetime => 0>> is necessary if you use | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | L<DBIx::Class::InflateColumn::DateTime>, and most people do, and still want to | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | be able to read these values. | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||
| 1175 | The values will come back as hexadecimal. | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||
| 1177 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||
| 1179 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||
| 1181 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||
| 1183 | Transitions to AutoCommit=0 (starting a transaction) mode by exhausting | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | any active cursors, using eager cursors. | ||||||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||||||
| 1186 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||
| 1188 | Real limits and limited counts using stored procedures deployed on startup. | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||
| 1190 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||
| 1192 | Blob update with a LIKE query on a blob, without invalidating the WHERE condition. | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||
| 1194 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||
| 1196 | bulk_insert using prepare_cached (see comments.) | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||
| 1198 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||
| 1200 | =head1 FURTHER QUESTIONS? | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||||||||||||||||
| 1202 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||
| 1204 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||
| 1206 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | redistribute it and/or modify it under the same terms as the | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. | ||||||||||||||||||||||||||||||||||||||||||