| 1 | package Rose::DB::Object; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 61 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 61 | ▶ | use Carp(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 61 | ▶ | use Rose::DB; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 61 | ▶ | use Rose::DB::Object::Metadata; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 61 | ▶ | use Rose::Object; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 61 | our @ISA = qw(Rose::Object); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 61 | ▶ | use Rose::DB::Object::Manager; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 61 | ▶ | use Rose::DB::Object::Constants qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 61 | ▶ | use Rose::DB::Constants qw(IN_TRANSACTION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 61 | ▶ | use Rose::DB::Object::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 61 | ▶ | use Rose::DB::Object::Util(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 61 | our $VERSION = '0.823'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 61 | our $Debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # Object data | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | use Rose::Object::MakeMethods::Generic | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 61 | ▶ | ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 61 | 'scalar' => [ 'error', 'not_found' ], | |||||||||||||||||||||||||||||||||||||||||
| 30 | 'boolean' => | ||||||||||||||||||||||||||||||||||||||||||
| 31 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 32 | #FLAG_DB_IS_PRIVATE, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | STATE_IN_DB, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | STATE_LOADING, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | STATE_SAVING, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 61 | ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # Class methods | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 96 | ▶ | sub meta_class { 'Rose::DB::Object::Metadata' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | sub meta | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 5937 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 5937 | my($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 5937 | ▶ | if(ref $self) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $self->{META_ATTR_NAME()} ||= $self->meta_class->for_class(ref $self); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"__xrdbopriv_meta"} ||= $self->meta_class->for_class(ref $self)
MC/DC0%0/2
$self->{"__xrdbopriv_meta"} ||= $self->meta_class->for_class(ref $self)
$self->{"__xrdbopriv_meta"}
$self->meta_class->for_class(ref $self)
Truth table0%0/3
A ||= B
A= $self->{"__xrdbopriv_meta"}B= $self->meta_class->for_class(ref $self)
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 5937 | ▶ | return $Rose::DB::Object::Metadata::Objects{$self} || | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Rose::DB::Object::Metadata::Objects{$self} || $self->meta_class->for_class($self)
MC/DC0%0/2
$Rose::DB::Object::Metadata::Objects{$self} || $self->meta_class->for_class($self)
$Rose::DB::Object::Metadata::Objects{$self}
$self->meta_class->for_class($self)
Truth table66%2/3
A || B
A= $Rose::DB::Object::Metadata::Objects{$self}B= $self->meta_class->for_class($self)
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | $self->meta_class->for_class($self); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # Object methods | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | sub db | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
db: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if(@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | #$self->{FLAG_DB_IS_PRIVATE()} = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $new_db = shift; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # If potentially migrating across db types, "suck through" the | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # driver-formatted values using the old db before swapping it | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # with the new one. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if($self->{LOADED_FROM_DRIVER()} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"__xrdbopriv_loaded_from_driver"} and $self->{"__xrdbopriv_loaded_from_driver"} ne $new_db->{"driver"}
MC/DC0%0/2
$self->{"__xrdbopriv_loaded_from_driver"} and $self->{"__xrdbopriv_loaded_from_driver"} ne $new_db->{"driver"}
$self->{"__xrdbopriv_loaded_from_driver"}
$self->{"__xrdbopriv_loaded_from_driver"} ne $new_db->{"driver"}
Truth table0%0/3
A and B
A= $self->{"__xrdbopriv_loaded_from_driver"}B= $self->{"__xrdbopriv_loaded_from_driver"} ne $new_db->{"driver"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | $self->{LOADED_FROM_DRIVER()} ne $new_db->{'driver'}) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | foreach my $method ($self->meta->column_accessor_method_names) | |||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # Need to catch return to avoid clever methods that | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # skip work when called in void context. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $val = $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->{'db'} = $new_db; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return $new_db; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return $self->{'db'} ||= $self->_init_db; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"db"} ||= $self->_init_db
MC/DC0%0/2
$self->{"db"} ||= $self->_init_db
$self->{"db"}
$self->_init_db
Truth table0%0/3
A ||= B
A= $self->{"db"}B= $self->_init_db
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 14 | ▶ | sub init_db { Rose::DB->new() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_db: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | sub _init_db | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_db: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my($db, $error); | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | eval { $db = $self->init_db }; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | unless($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | #$self->{FLAG_DB_IS_PRIVATE()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return $db; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if(ref $error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->error($error); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | else | ||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $self->error("Could not init_db() - $error - " . ($db ? $db->error : '')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | sub dbh | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my $db = $self->db or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if(my $dbh = $db->dbh(@_)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return $dbh; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | else | ||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->error($db->error); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 61 | ▶ | use constant LAZY_LOADED_KEY => | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 61 | Rose::DB::Object::Util::lazy_column_values_loaded_key(); | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub load | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=48 SCAR=76.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my($self) = $_[0]; # XXX: Must maintain alias to actual "self" object arg | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my %args = (self => @_); # faster than @_[1 .. $#_]; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $db = $self->db or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my $dbh = $self->dbh or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $meta = $self->meta; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | my $prepare_cached = | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | exists $args{'prepare_cached'} ? $args{'prepare_cached'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | $meta->dbi_prepare_cached; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | local $self->{STATE_SAVING()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | local $self->{SAVING_FOR_LOAD()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my(@key_columns, @key_methods, @key_values); | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $null_key = 0; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $found_key = 0; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if(my $key = delete $args{'use_key'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my @uk = grep { $_->name eq $key } $meta->unique_keys; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if(@uk == 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $defined = 0; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | @key_columns = $uk[0]->column_names; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | @key_methods = map { $meta->column_accessor_method_name($_) } @key_columns; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | @key_values = map { $defined++ if(defined $_); $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | map { $self->$_() } @key_methods; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | unless($defined) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $self->error("Could not load() based on key '$key' - column(s) have undefined values"); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if(@key_values != $defined) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $null_key = 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | else { Carp::croak "No unique key named '$key' is defined in ", ref($self) } | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | else | ||||||||||||||||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | @key_columns = $meta->primary_key_column_names; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | @key_methods = $meta->primary_key_column_accessor_names; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | @key_values = grep { defined } map { $self->$_() } @key_methods; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | unless(@key_values == @key_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $alt_columns; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | # Prefer unique keys where we have defined values for all | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # key columns, but fall back to the first unique key found | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # where we have at least one defined value. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | foreach my $cols ($meta->unique_keys_column_names) | |||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $defined = 0; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | @key_columns = @$cols; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | @key_methods = map { $meta->column_accessor_method_name($_) } @key_columns; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | @key_values = map { $defined++ if(defined $_); $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | map { $self->$_() } @key_methods; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if($defined == @key_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $found_key = 1; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $alt_columns ||= $cols if($defined); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$alt_columns ||= $cols
MC/DC0%0/2
$alt_columns ||= $cols
$alt_columns
$cols
Truth table0%0/3
A ||= B
A= $alt_columnsB= $cols
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if(!$found_key && $alt_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $found_key and $alt_columns
MC/DC0%0/2
not $found_key and $alt_columns
not $found_key
$alt_columns
Truth table0%0/3
not(A) and B
A= not $found_keyB= $alt_columns
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | @key_columns = @$alt_columns; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | @key_methods = map { $meta->column_accessor_method_name($_) } @key_columns; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | @key_values = map { $self->$_() } @key_methods; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $null_key = 1; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $found_key = 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | unless($found_key) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | @key_columns = $meta->primary_key_column_names; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my $e = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | Rose::DB::Object::Exception->new( | ||||||||||||||||||||||||||||||||||||||||||
| 243 | message => "Cannot load " . ref($self) . " without a primary key (" . | ||||||||||||||||||||||||||||||||||||||||||
| 244 | join(', ', @key_columns) . ') with ' . | ||||||||||||||||||||||||||||||||||||||||||
| 245 | (@key_columns > 1 ? 'non-null values in all columns' : | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 'a non-null value') . | ||||||||||||||||||||||||||||||||||||||||||
| 247 | ' or another unique key with at least one non-null value.', | ||||||||||||||||||||||||||||||||||||||||||
| 248 | code => EXCEPTION_CODE_NO_KEY); | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $self->error($e); | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my $has_lazy_columns = $args{'nonlazy'} ? 0 : $meta->has_lazy_columns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $column_names; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if($has_lazy_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $column_names = $meta->nonlazy_column_names; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $self->{LAZY_LOADED_KEY()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | else | ||||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $column_names = $meta->column_names; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # Coerce for_update boolean alias into lock argument | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if(delete $args{'for_update'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | $args{'lock'}{'type'} ||= 'for update'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"lock"}{"type"} ||= "for update"
MC/DC0%0/1
$args{"lock"}{"type"} ||= "for update"
$args{"lock"}{"type"}
Truth table0%0/2
A
A= $args{"lock"}{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # | ||||||||||||||||||||||||||||||||||||||||||
| 278 | # Handle sub-object load in separate code path | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if(my $with = $args{'with'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $mgr_class = $args{'manager_class'} || 'Rose::DB::Object::Manager'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'manager_class'} || 'Rose::DB::Object::Manager'
MC/DC0%0/1
$args{'manager_class'} || 'Rose::DB::Object::Manager'
$args{'manager_class'}
Truth table0%0/2
A
A= $args{'manager_class'}
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my %query; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | @query{map { "t1.$_" } @key_columns} = @key_values; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my($objects, $error); | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 296 | $objects = | ||||||||||||||||||||||||||||||||||||||||||
| 297 | $mgr_class->get_objects(object_class => ref $self, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 299 | query => [ %query ], | ||||||||||||||||||||||||||||||||||||||||||
| 300 | with_objects => $with, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | multi_many_ok => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | nonlazy => $args{'nonlazy'}, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | inject_results => $args{'inject_results'}, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | lock => $args{'lock'}, | ||||||||||||||||||||||||||||||||||||||||||
| 305 | (exists $args{'prepare_cached'} ? | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | (prepare_cached => $args{'prepare_cached'}) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | ())) | ||||||||||||||||||||||||||||||||||||||||||
| 308 | or Carp::confess $mgr_class->error; | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if(@$objects > 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | die "Found ", @$objects, " objects instead of one"; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | { | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $self->error(ref $error ? $error : "load(with => ...) - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if(@$objects > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # Sneaky init by object replacement | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $self = $_[0] = $objects->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | # Init by copying attributes (broken; need to do fks and relationships too) | ||||||||||||||||||||||||||||||||||||||||||
| 332 | #my $methods = $meta->column_mutator_method_names; | ||||||||||||||||||||||||||||||||||||||||||
| 333 | #my $object = $objects->[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 334 | # | ||||||||||||||||||||||||||||||||||||||||||
| 335 | #local $self->{STATE_LOADING()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 336 | #local $object->{STATE_SAVING()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # | ||||||||||||||||||||||||||||||||||||||||||
| 338 | #foreach my $method (@$methods) | ||||||||||||||||||||||||||||||||||||||||||
| 339 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # $self->$method($object->$method()); | ||||||||||||||||||||||||||||||||||||||||||
| 341 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | else | ||||||||||||||||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $self->error("No such " . ref($self) . ' where ' . | |||||||||||||||||||||||||||||||||||||||||
| 347 | join(', ', @key_columns) . ' = ' . join(', ', @key_values)); | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $self->{'not_found'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $self->{STATE_IN_DB()} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | my $speculative = | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | exists $args{'speculative'} ? $args{'speculative'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | $meta->default_load_speculative; | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | unless($speculative) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $self->{STATE_IN_DB()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $self->{LOADED_FROM_DRIVER()} = $db->{'driver'}; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | return $self || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | # | ||||||||||||||||||||||||||||||||||||||||||
| 371 | # Handle normal load | ||||||||||||||||||||||||||||||||||||||||||
| 372 | # | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my($loaded_ok, $error); | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $self->{'not_found'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 379 | { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | local $self->{STATE_LOADING()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | local $dbh->{'RaiseError'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my($sql, $sth); | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if($null_key) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if($has_lazy_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $sql = $meta->load_sql_with_null_key(\@key_columns, \@key_values, $db); | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | else | ||||||||||||||||||||||||||||||||||||||||||
| 396 | { | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | $sql = $meta->load_all_sql_with_null_key(\@key_columns, \@key_values, $db); | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | else | ||||||||||||||||||||||||||||||||||||||||||
| 401 | { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if($has_lazy_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $sql = $meta->load_sql(\@key_columns, $db); | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | else | ||||||||||||||||||||||||||||||||||||||||||
| 407 | { | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $sql = $meta->load_all_sql(\@key_columns, $db); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if(my $lock = $args{'lock'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | { | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $sql .= ' ' . $db->format_select_lock($self, $lock); | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | # $meta->prepare_select_options (defunct) | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | $dbh->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | $Debug && warn "$sql - bind params: ", join(', ', grep { defined } @key_values), "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $sth->execute(grep { defined } @key_values); | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my %row; | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $sth->bind_columns(undef, \@row{@$column_names}); | |||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $loaded_ok = defined $sth->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | # The load() query shouldn't find more than one row anyway, | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # but DBD::SQLite demands this :-/ | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # XXX: Recent versions of DBD::SQLite seem to have cured this. | ||||||||||||||||||||||||||||||||||||||||||
| 433 | # XXX: Safe to remove? | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if($loaded_ok) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | { | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $methods = $meta->column_mutator_method_names_hash; | |||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | # Empty existing object? | ||||||||||||||||||||||||||||||||||||||||||
| 441 | #%$self = (db => $self->db, meta => $meta, STATE_LOADING() => 1); | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | foreach my $name (@$column_names) | |||||||||||||||||||||||||||||||||||||||||
| 444 | { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $method = $methods->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $self->$method($row{$name}); | |||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | # Sneaky init by object replacement | ||||||||||||||||||||||||||||||||||||||||||
| 450 | #my $object = (ref $self)->new(db => $self->db); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | # | ||||||||||||||||||||||||||||||||||||||||||
| 452 | #foreach my $name (@$column_names) | ||||||||||||||||||||||||||||||||||||||||||
| 453 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # my $method = $methods->{$name}; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | # $object->$method($row{$name}); | ||||||||||||||||||||||||||||||||||||||||||
| 456 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 457 | # | ||||||||||||||||||||||||||||||||||||||||||
| 458 | #$self = $_[0] = $object; | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | else | ||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $self->error("No such " . ref($self) . ' where ' . | |||||||||||||||||||||||||||||||||||||||||
| 464 | join(', ', @key_columns) . ' = ' . join(', ', @key_values)); | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $self->{'not_found'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $self->{STATE_IN_DB()} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $self->error(ref $error ? $error : "load() - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | unless($loaded_ok) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | my $speculative = | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | exists $args{'speculative'} ? $args{'speculative'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | $meta->default_load_speculative; | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | unless($speculative) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | { | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $self->{STATE_IN_DB()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $self->{LOADED_FROM_DRIVER()} = $db->{'driver'}; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | return $self || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | sub save | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: not called CC=52 SCAR=79.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $meta = $self->meta; | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | my $cascade = | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | exists $args{'cascade'} ? $args{'cascade'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | $meta->default_cascade_save; | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | # Keep trigger-encumbered and cascade code in separate code path | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if($self->{ON_SAVE_ATTR_NAME()} || $cascade) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"__xrdbopriv_on_save"} or $cascade
MC/DC0%0/2
$self->{"__xrdbopriv_on_save"} or $cascade
$self->{"__xrdbopriv_on_save"}
$cascade
Truth table0%0/3
A or B
A= $self->{"__xrdbopriv_on_save"}B= $cascade
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | { | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | my $db = $args{'db'} || $self->db || return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$args{'db'} || $self->db || (return 0)
$args{"db"} or $self->db
MC/DC0%0/2
$args{'db'} || $self->db || (return 0)
$args{"db"}
$self->db
Truth table0%0/3
A or B
A= $args{"db"}B= $self->db
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $ret = $db->begin_work; | |||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | $args{'db'} ||= $db; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{"db"} ||= $db
MC/DC0%0/2
$args{"db"} ||= $db
$args{"db"}
$db
Truth table0%0/3
A ||= B
A= $args{"db"}B= $db
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | unless($ret) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | { | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my $error = $db->error; | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | $self->error(ref $error ? $error : "Could not begin transaction before saving - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | my $started_new_tx = ($ret == IN_TRANSACTION) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 531 | { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my %did_set; | |||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | my %code_args = | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | map { ($_ => $args{$_}) } grep { exists $args{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 540 | qw(changes_only prepare_cached cascade); | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | # | ||||||||||||||||||||||||||||||||||||||||||
| 543 | # Do pre-save stuff | ||||||||||||||||||||||||||||||||||||||||||
| 544 | # | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my $todo = $self->{ON_SAVE_ATTR_NAME()}{'pre'}; | |||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | foreach my $fk_name (keys %{$todo->{'fk'}}) | |||||||||||||||||||||||||||||||||||||||||
| 549 | { | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | my $code = $todo->{'fk'}{$fk_name}{'set'} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | my $object = $code->($self, \%code_args); | |||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | # Account for objects that evaluate to false to due overloading | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | unless($object || ref $object) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$object or ref $object
MC/DC0%0/2
$object or ref $object
$object
ref $object
Truth table0%0/3
A or B
A= $objectB= ref $object
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | { | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | die $self->error; | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | # Track which rows were set so we can avoid deleting | ||||||||||||||||||||||||||||||||||||||||||
| 560 | # them later in the "delete on save" code | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $did_set{'fk'}{$fk_name}{Rose::DB::Object::Util::row_id($object)} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | # | ||||||||||||||||||||||||||||||||||||||||||
| 565 | # Do the actual save | ||||||||||||||||||||||||||||||||||||||||||
| 566 | # | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | if(!$args{'insert'} && ($args{'update'} || $self->{STATE_IN_DB()})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $args{"insert"} and $args{"update"} || $self->{"__xrdbopriv_in_db"}
$args{"update"} or $self->{"__xrdbopriv_in_db"}
MC/DC0%0/3
not $args{"insert"} and $args{"update"} || $self->{"__xrdbopriv_in_db"}
not $args{"insert"}
$args{"update"}
$self->{"__xrdbopriv_in_db"}
Truth table0%0/4
not(A) and B or C
A= not $args{"insert"}B= $args{"update"}C= $self->{"__xrdbopriv_in_db"}
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | { | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $ret = shift->update(@_); | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | else | ||||||||||||||||||||||||||||||||||||||||||
| 573 | { | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $ret = shift->insert(@_); | |||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | # | ||||||||||||||||||||||||||||||||||||||||||
| 578 | # Do post-save stuff | ||||||||||||||||||||||||||||||||||||||||||
| 579 | # | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $todo = $self->{ON_SAVE_ATTR_NAME()}{'post'}; | |||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | # Foreign keys (and some fk-like relationships) | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | foreach my $fk_name (keys %{$todo->{'fk'}}) | |||||||||||||||||||||||||||||||||||||||||
| 585 | { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | foreach my $item (@{$todo->{'fk'}{$fk_name}{'delete'} || []}) | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$todo->{'fk'}{$fk_name}{'delete'} || []
MC/DC0%0/1
$todo->{'fk'}{$fk_name}{'delete'} || []
$todo->{'fk'}{$fk_name}{'delete'}
Truth table0%0/2
A
A= $todo->{'fk'}{$fk_name}{'delete'}
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | { | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $code = $item->{'code'}; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | my $object = $item->{'object'}; | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | # Don't run the code to delete this object if we just set it above | ||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | next if($did_set{'fk'}{$fk_name}{Rose::DB::Object::Util::row_id($object)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | $code->($self, \%code_args) or die $self->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if($cascade) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | { | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | foreach my $fk ($meta->foreign_keys) | |||||||||||||||||||||||||||||||||||||||||
| 601 | { | ||||||||||||||||||||||||||||||||||||||||||
| 602 | # If this object was just set above, just save changes (there | ||||||||||||||||||||||||||||||||||||||||||
| 603 | # should be none) as a way to continue the cascade | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | local $args{'changes_only'} = 1 if($todo->{'fk'}{$fk->name}{'set'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | my $foreign_object = $fk->object_has_foreign_object($self) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fk->object_has_foreign_object($self) || (next)
MC/DC0%0/1
$fk->object_has_foreign_object($self) || (next)
$fk->object_has_foreign_object($self)
Truth table0%0/2
A
A= $fk->object_has_foreign_object($self)
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | if(Rose::DB::Object::Util::has_modified_columns($foreign_object) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
Rose::DB::Object::Util::has_modified_columns($foreign_object) or Rose::DB::Object::Util::has_modified_children($foreign_object)
MC/DC0%0/2
Rose::DB::Object::Util::has_modified_columns($foreign_object) or Rose::DB::Object::Util::has_modified_children($foreign_object)
Rose::DB::Object::Util::has_modified_columns($foreign_object)
Rose::DB::Object::Util::has_modified_children($foreign_object)
Truth table0%0/3
A or B
A= Rose::DB::Object::Util::has_modified_columns($foreign_object)B= Rose::DB::Object::Util::has_modified_children($foreign_object)
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | Rose::DB::Object::Util::has_modified_children($foreign_object)) | ||||||||||||||||||||||||||||||||||||||||||
| 610 | { | ||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | $Debug && warn "$self - save foreign ", $fk->name, " - $foreign_object\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | $foreign_object->save(%args); | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | # Relationships | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | foreach my $rel_name (keys %{$todo->{'rel'}}) | |||||||||||||||||||||||||||||||||||||||||
| 619 | { | ||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my $code; | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | # Set value(s) | ||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | if($code = $todo->{'rel'}{$rel_name}{'set'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | { | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | $code->($self, \%code_args) or die $self->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | # Delete value(s) | ||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | if($code = $todo->{'rel'}{$rel_name}{'delete'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | { | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | $code->($self, \%code_args) or die $self->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | # Add value(s) | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | if($code = $todo->{'rel'}{$rel_name}{'add'}{'code'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | { | ||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | $code->($self, \%code_args) or die $self->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if($cascade) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | foreach my $rel ($meta->relationships) | |||||||||||||||||||||||||||||||||||||||||
| 644 | { | ||||||||||||||||||||||||||||||||||||||||||
| 645 | # If this object was just set above, just save changes (there | ||||||||||||||||||||||||||||||||||||||||||
| 646 | # should be none) as a way to continue the cascade | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | local $args{'changes_only'} = 1 if($todo->{'rel'}{$rel->name}{'set'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | my $related_objects = $rel->object_has_related_objects($self) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rel->object_has_related_objects($self) || (next)
MC/DC0%0/1
$rel->object_has_related_objects($self) || (next)
$rel->object_has_related_objects($self)
Truth table0%0/2
A
A= $rel->object_has_related_objects($self)
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | foreach my $related_object (@$related_objects) | |||||||||||||||||||||||||||||||||||||||||
| 652 | { | ||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | if(Rose::DB::Object::Util::has_modified_columns($related_object) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
Rose::DB::Object::Util::has_modified_columns($related_object) or Rose::DB::Object::Util::has_modified_children($related_object)
MC/DC0%0/2
Rose::DB::Object::Util::has_modified_columns($related_object) or Rose::DB::Object::Util::has_modified_children($related_object)
Rose::DB::Object::Util::has_modified_columns($related_object)
Rose::DB::Object::Util::has_modified_children($related_object)
Truth table0%0/3
A or B
A= Rose::DB::Object::Util::has_modified_columns($related_object)B= Rose::DB::Object::Util::has_modified_children($related_object)
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | Rose::DB::Object::Util::has_modified_children($related_object)) | ||||||||||||||||||||||||||||||||||||||||||
| 655 | { | ||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | $Debug && warn "$self - save related ", $rel->name, " - $related_object\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | $related_object->save(%args); | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | ▶ | if($started_new_tx) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | { | ||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | ▶ | $db->commit or die $db->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | delete $self->{ON_SAVE_ATTR_NAME()}; | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | { | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | $self->error($error); | |||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | $db->rollback or warn $db->error if($started_new_tx); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$started_new_tx && ($db->rollback || warn($db->error))
$db->rollback or warn $db->error
MC/DC0%0/2
$started_new_tx && ($db->rollback || warn($db->error))
$started_new_tx
$db->rollback
Truth table0%0/3
A && B
A= $started_new_txB= $db->rollback
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | else | ||||||||||||||||||||||||||||||||||||||||||
| 687 | { | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if(!$args{'insert'} && ($args{'update'} || $self->{STATE_IN_DB()})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $args{"insert"} and $args{"update"} || $self->{"__xrdbopriv_in_db"}
$args{"update"} or $self->{"__xrdbopriv_in_db"}
MC/DC0%0/3
not $args{"insert"} and $args{"update"} || $self->{"__xrdbopriv_in_db"}
not $args{"insert"}
$args{"update"}
$self->{"__xrdbopriv_in_db"}
Truth table0%0/4
not(A) and B or C
A= not $args{"insert"}B= $args{"update"}C= $self->{"__xrdbopriv_in_db"}
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | { | ||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | return shift->update(@_); | |||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | return shift->insert(@_); | |||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | sub update | ||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=45 SCAR=74.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | my $db = $self->db or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | my $dbh = $self->dbh or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | my $meta = $self->meta; | |||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | my $prepare_cached = | ||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | exists $args{'prepare_cached'} ? $args{'prepare_cached'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | $meta->dbi_prepare_cached; | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | my $changes_only = | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | exists $args{'changes_only'} ? $args{'changes_only'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | $meta->default_update_changes_only; | ||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | local $self->{STATE_SAVING()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | my @key_columns = $meta->primary_key_column_names; | |||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | my @key_methods = $meta->primary_key_column_accessor_names; | |||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my @key_values = grep { defined } map { $self->$_() } @key_methods; | |||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | # Special case for tables where all columns are part of the primary key | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | return $self || 1 if(@key_columns == $meta->num_columns); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | # See comment below | ||||||||||||||||||||||||||||||||||||||||||
| 724 | #my $null_key = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 725 | #my $found_key = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | unless(@key_values == @key_columns) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | { | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | $self->error("Cannot update " . ref($self) . " without a primary key (" . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | join(', ', @key_columns) . ') with ' . | ||||||||||||||||||||||||||||||||||||||||||
| 731 | (@key_columns > 1 ? 'non-null values in all columns' : | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 'a non-null value')); | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | #my $ret = $db->begin_work; | ||||||||||||||||||||||||||||||||||||||||||
| 738 | # | ||||||||||||||||||||||||||||||||||||||||||
| 739 | #unless($ret) | ||||||||||||||||||||||||||||||||||||||||||
| 740 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 741 | # my $error = $db->error; | ||||||||||||||||||||||||||||||||||||||||||
| 742 | # $self->error(ref $error ? $error : "Could not begin transaction before updating - $error"); | ||||||||||||||||||||||||||||||||||||||||||
| 743 | # return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 744 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 745 | # | ||||||||||||||||||||||||||||||||||||||||||
| 746 | #my $started_new_tx = ($ret == Rose::DB::Constants::IN_TRANSACTION) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 751 | { | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 756 | #local $self->{STATE_SAVING()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | local $dbh->{'RaiseError'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | my $sth; | |||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | if($meta->allow_inline_column_values) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | { | ||||||||||||||||||||||||||||||||||||||||||
| 763 | # This versions of update_sql_with_inlining is not needed (see comments | ||||||||||||||||||||||||||||||||||||||||||
| 764 | # in Rose/DB/Object/Metadata.pm for more information) | ||||||||||||||||||||||||||||||||||||||||||
| 765 | #my($sql, $bind) = | ||||||||||||||||||||||||||||||||||||||||||
| 766 | # $meta->update_sql_with_inlining($self, \@key_columns, \@key_values); | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | my($sql, $bind, $bind_params); | |||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | if($changes_only) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | { | ||||||||||||||||||||||||||||||||||||||||||
| 772 | # No changes to save... | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | return $self || 1 unless(%{$self->{MODIFIED_COLUMNS()} || {}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$self->{'__xrdbopriv_modified_columns'} || {}
$self || 1
MC/DC0%0/1
$self->{'__xrdbopriv_modified_columns'} || {}
$self->{'__xrdbopriv_modified_columns'}
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self->{'__xrdbopriv_modified_columns'}
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ($sql, $bind, $bind_params) = | |||||||||||||||||||||||||||||||||||||||||
| 775 | $meta->update_changes_only_sql_with_inlining($self, \@key_columns); | ||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | ▶ | unless($sql) # skip key-only updates | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | { | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | ▶ | return $self || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | else | ||||||||||||||||||||||||||||||||||||||||||
| 784 | { | ||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ($sql, $bind, $bind_params) = $meta->update_sql_with_inlining($self, \@key_columns); | |||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | { | ||||||||||||||||||||||||||||||||||||||||||
| 790 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | warn "$sql - bind params: ", join(', ', @$bind, @key_values), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $sth = $dbh->prepare($sql); #, $meta->prepare_update_options); | |||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | if($bind_params) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | { | ||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | foreach my $value (@$bind) | |||||||||||||||||||||||||||||||||||||||||
| 801 | { | ||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | $sth->bind_param($i, $value, $bind_params->[$i - 1]); | |||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | my $kv_idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | foreach my $column_name (@key_columns) | |||||||||||||||||||||||||||||||||||||||||
| 809 | { | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | my $column = $meta->column($column_name); | |||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | $sth->bind_param($i++, $key_values[$kv_idx++], $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||
| 816 | else | ||||||||||||||||||||||||||||||||||||||||||
| 817 | { | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | $sth->execute(@$bind, @key_values); | |||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||
| 821 | else | ||||||||||||||||||||||||||||||||||||||||||
| 822 | { | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | if($changes_only) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | { | ||||||||||||||||||||||||||||||||||||||||||
| 825 | # No changes to save... | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | return $self || 1 unless(%{$self->{MODIFIED_COLUMNS()} || {}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$self->{'__xrdbopriv_modified_columns'} || {}
$self || 1
MC/DC0%0/1
$self->{'__xrdbopriv_modified_columns'} || {}
$self->{'__xrdbopriv_modified_columns'}
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self->{'__xrdbopriv_modified_columns'}
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | my($sql, $bind, $columns) = $meta->update_changes_only_sql($self, \@key_columns, $db); | |||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | unless($sql) # skip key-only updates | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | { | ||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | ▶ | return $self || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | # $meta->prepare_update_options (defunct) | ||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | $dbh->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | { | ||||||||||||||||||||||||||||||||||||||||||
| 842 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | warn "$sql - bind params: ", join(', ', @$bind, @key_values), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | ▶ | if($meta->dbi_requires_bind_param($db)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | { | ||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | foreach my $column (@$columns) | |||||||||||||||||||||||||||||||||||||||||
| 851 | { | ||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | my $method = $column->accessor_method_name; | |||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | $sth->bind_param($i++, $self->$method(), $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | my $kv_idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | foreach my $column_name (@key_columns) | |||||||||||||||||||||||||||||||||||||||||
| 859 | { | ||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | my $column = $meta->column($column_name); | |||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | $sth->bind_param($i++, $key_values[$kv_idx++], $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||
| 866 | else | ||||||||||||||||||||||||||||||||||||||||||
| 867 | { | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | $sth->execute(@$bind, @key_values); | |||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||
| 871 | elsif($meta->has_lazy_columns) | ||||||||||||||||||||||||||||||||||||||||||
| 872 | { | ||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | my($sql, $bind, $columns) = $meta->update_sql($self, \@key_columns, $db); | |||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | # $meta->prepare_update_options (defunct) | ||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | ▶ | my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 877 | $dbh->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 880 | { | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | warn "$sql - bind params: ", join(', ', @$bind, @key_values), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | ▶ | if($meta->dbi_requires_bind_param($db)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | { | ||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | foreach my $column (@$columns) | |||||||||||||||||||||||||||||||||||||||||
| 890 | { | ||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | my $method = $column->accessor_method_name; | |||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | $sth->bind_param($i++, $self->$method(), $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | my $kv_idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | foreach my $column_name (@key_columns) | |||||||||||||||||||||||||||||||||||||||||
| 898 | { | ||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | my $column = $meta->column($column_name); | |||||||||||||||||||||||||||||||||||||||||
| 900 | 0 | $sth->bind_param($i++, $key_values[$kv_idx++], $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||
| 905 | else | ||||||||||||||||||||||||||||||||||||||||||
| 906 | { | ||||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | $sth->execute(@$bind, @key_values); | |||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||
| 910 | else | ||||||||||||||||||||||||||||||||||||||||||
| 911 | { | ||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | my $sql = $meta->update_all_sql(\@key_columns, $db); | |||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | # $meta->prepare_update_options (defunct) | ||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | $dbh->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | my %key = map { ($_ => 1) } @key_methods; | |||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | my $method_names = $meta->column_accessor_method_names; | |||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 923 | { | ||||||||||||||||||||||||||||||||||||||||||
| 924 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 925 | warn "$sql - bind params: ", | ||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | join(', ', (map { $self->$_() } grep { !$key{$_} } @$method_names), | |||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | grep { defined } @key_values), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | if($meta->dbi_requires_bind_param($db)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 931 | { | ||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | foreach my $column (grep { !$key{$_->name} } $meta->columns_ordered) | |||||||||||||||||||||||||||||||||||||||||
| 935 | { | ||||||||||||||||||||||||||||||||||||||||||
| 936 | 0 | my $method = $column->accessor_method_name; | |||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | $sth->bind_param($i++, $self->$method(), $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | foreach my $column_name (@key_columns) | |||||||||||||||||||||||||||||||||||||||||
| 941 | { | ||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | my $column = $meta->column($column_name); | |||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | my $method = $column->accessor_method_name; | |||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | $sth->bind_param($i++, $self->$method(), $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||
| 949 | else | ||||||||||||||||||||||||||||||||||||||||||
| 950 | { | ||||||||||||||||||||||||||||||||||||||||||
| 951 | $sth->execute( | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | (map { $self->$_() } grep { !$key{$_} } @$method_names), | |||||||||||||||||||||||||||||||||||||||||
| 953 | @key_values); | ||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||
| 957 | #if($started_new_tx) | ||||||||||||||||||||||||||||||||||||||||||
| 958 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 959 | # $db->commit or die $db->error; | ||||||||||||||||||||||||||||||||||||||||||
| 960 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 961 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 967 | { | ||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | ▶ | $self->error(ref $error ? $error : "update() - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 969 | #$db->rollback or warn $db->error if($started_new_tx); | ||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | $self->{STATE_IN_DB()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | return $self || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||
| 980 | sub insert | ||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=43 SCAR=74.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | ▶ | my $db = $self->db or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | ▶ | my $dbh = $self->dbh or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | my $meta = $self->meta; | |||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||
| 989 | my $prepare_cached = | ||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | exists $args{'prepare_cached'} ? $args{'prepare_cached'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 991 | $meta->dbi_prepare_cached; | ||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||
| 993 | my $changes_only = | ||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | ▶ | exists $args{'changes_only'} ? $args{'changes_only'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 995 | $meta->default_insert_changes_only; | ||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | local $self->{STATE_SAVING()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | my @pk_methods = $meta->primary_key_column_accessor_names; | |||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | my @pk_values = grep { defined } map { $self->$_() } @pk_methods; | |||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | #my $ret = $db->begin_work; | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | #unless($ret) | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | # my $error = $db->error; | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | # $self->error(ref $error ? $error : "Could not begin transaction before inserting - $error"); | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | # return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1011 | #my $started_new_tx = ($ret > 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | 0 | my $using_pk_placeholders = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | ▶ | unless(@pk_values == @pk_methods || $args{'on_duplicate_key_update'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@pk_values == @pk_methods or $args{"on_duplicate_key_update"}
MC/DC0%0/2
@pk_values == @pk_methods or $args{"on_duplicate_key_update"}
@pk_values == @pk_methods
$args{"on_duplicate_key_update"}
Truth table0%0/3
A or B
A= @pk_values == @pk_methodsB= $args{"on_duplicate_key_update"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1016 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | my @generated_pk_values = $meta->generate_primary_key_values($db); | |||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | ▶ | unless(@generated_pk_values) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1020 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | @generated_pk_values = $meta->generate_primary_key_placeholders($db); | |||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | $using_pk_placeholders = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | ▶ | unless(@generated_pk_values == @pk_methods) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1026 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | my $s = (@pk_values == 1 ? '' : 's'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | $self->error("Could not generate primary key$s for column$s " . | |||||||||||||||||||||||||||||||||||||||||
| 1029 | join(', ', @pk_methods)); | ||||||||||||||||||||||||||||||||||||||||||
| 1030 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | my @pk_set_methods = map { $meta->column_mutator_method_name($_) } | |||||||||||||||||||||||||||||||||||||||||
| 1035 | $meta->primary_key_column_names; | ||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | foreach my $name (@pk_set_methods) | |||||||||||||||||||||||||||||||||||||||||
| 1040 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | my $pk_value = shift @generated_pk_values; | |||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | next unless(defined $pk_value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | $self->$name($pk_value); | |||||||||||||||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1045 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||
| 1049 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 1055 | #local $self->{STATE_SAVING()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | local $dbh->{'RaiseError'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||
| 1058 | #my $options = $meta->prepare_insert_options; | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | my $sth; | |||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | ▶ | if($meta->allow_inline_column_values) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1063 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | my($sql, $bind, $bind_params); | |||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | ▶ | if($args{'on_duplicate_key_update'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1067 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | ($sql, $bind, $bind_params) = | |||||||||||||||||||||||||||||||||||||||||
| 1069 | $meta->insert_and_on_duplicate_key_update_with_inlining_sql( | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | $self, $db, $changes_only); | ||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | elsif($changes_only) | ||||||||||||||||||||||||||||||||||||||||||
| 1073 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | ($sql, $bind, $bind_params) = $meta->insert_changes_only_sql_with_inlining($self); | |||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | ($sql, $bind, $bind_params) = $meta->insert_sql_with_inlining($self); | |||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1082 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | warn "$sql - bind params: ", join(', ', @$bind), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | $sth = $dbh->prepare($sql); #, $options); | |||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | ▶ | if($bind_params) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1090 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||
| 1093 | 0 | foreach my $value (@$bind) | |||||||||||||||||||||||||||||||||||||||||
| 1094 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | $sth->bind_param($i, $value, $bind_params->[$i - 1]); | |||||||||||||||||||||||||||||||||||||||||
| 1096 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1101 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | $sth->execute(@$bind); | |||||||||||||||||||||||||||||||||||||||||
| 1104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | 0 | my $column_names = $meta->column_names; | |||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | ▶ | if($args{'on_duplicate_key_update'} || $changes_only) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"on_duplicate_key_update"} or $changes_only
MC/DC0%0/2
$args{"on_duplicate_key_update"} or $changes_only
$args{"on_duplicate_key_update"}
$changes_only
Truth table0%0/3
A or B
A= $args{"on_duplicate_key_update"}B= $changes_only
| |||||||||||||||||||||||||||||||||||||||||||
| 1111 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | 0 | my($sql, $bind, $columns); | |||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | if($args{'on_duplicate_key_update'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ($sql, $bind, $columns) = | |||||||||||||||||||||||||||||||||||||||||
| 1117 | $meta->insert_and_on_duplicate_key_update_sql( | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | $self, $db, $changes_only); | ||||||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | ($sql, $bind, $columns) = $meta->insert_changes_only_sql($self, $db); | |||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1126 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | warn $sql, " - bind params: @$bind\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | ▶ | $sth = $prepare_cached ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1132 | $dbh->prepare_cached($sql, undef, 3) : | ||||||||||||||||||||||||||||||||||||||||||
| 1133 | $dbh->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | ▶ | if($meta->dbi_requires_bind_param($db)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1136 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | foreach my $column (@$columns) | |||||||||||||||||||||||||||||||||||||||||
| 1140 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | my $method = $column->accessor_method_name; | |||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | $sth->bind_param($i++, $self->$method(), $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | $sth->execute(@$bind); | |||||||||||||||||||||||||||||||||||||||||
| 1150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1152 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | ▶ | $sth = $prepare_cached ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1155 | $dbh->prepare_cached($meta->insert_sql($db), undef, 3) : | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | $dbh->prepare($meta->insert_sql($db)); | ||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||
| 1158 | 0 | ▶ | if($Debug) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1159 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | 61 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1161 | warn $meta->insert_sql($db), " - bind params: ", | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | 0 | join(', ', (map {$self->$_()} $meta->column_accessor_method_names)), | |||||||||||||||||||||||||||||||||||||||||
| 1163 | "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | #$sth->execute(map { $self->$_() } $meta->column_accessor_method_names); | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | ▶ | if($meta->dbi_requires_bind_param($db)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1169 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | foreach my $column ($meta->columns_ordered) | |||||||||||||||||||||||||||||||||||||||||
| 1173 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | my $method = $column->accessor_method_name; | |||||||||||||||||||||||||||||||||||||||||
| 1175 | 0 | $sth->bind_param($i++, $self->$method(), $column->dbi_bind_param_attrs($db)); | |||||||||||||||||||||||||||||||||||||||||
| 1176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1181 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | 0 | $sth->execute(map { $self->$_() } $meta->column_accessor_method_names); | |||||||||||||||||||||||||||||||||||||||||
| 1183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | ▶ | if(@pk_methods == 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1188 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | 0 | my $get_pk = $pk_methods[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | ▶ | if($using_pk_placeholders || !defined $self->$get_pk()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$using_pk_placeholders or not defined $self->$get_pk
MC/DC0%0/2
$using_pk_placeholders or not defined $self->$get_pk
$using_pk_placeholders
not defined $self->$get_pk
Truth table0%0/3
A or not(B)
A= $using_pk_placeholdersB= not defined $self->$get_pk
| |||||||||||||||||||||||||||||||||||||||||||
| 1192 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | local $self->{STATE_LOADING()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | my $set_pk = $meta->column_mutator_method_name($meta->primary_key_column_names); | |||||||||||||||||||||||||||||||||||||||||
| 1195 | #$self->$set_pk($db->last_insertid_from_sth($sth, $self)); | ||||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | $self->$set_pk($db->last_insertid_from_sth($sth)); | |||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | $self->{STATE_IN_DB()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | ▶ | elsif(!$using_pk_placeholders && defined $self->$get_pk()) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $using_pk_placeholders and defined $self->$get_pk
MC/DC0%0/2
not $using_pk_placeholders and defined $self->$get_pk
not $using_pk_placeholders
defined $self->$get_pk
Truth table0%0/3
not(A) and B
A= not $using_pk_placeholdersB= defined $self->$get_pk
| |||||||||||||||||||||||||||||||||||||||||||
| 1200 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | $self->{STATE_IN_DB()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | elsif(@pk_values == @pk_methods) | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | 0 | $self->{STATE_IN_DB()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | elsif(!$using_pk_placeholders) | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | my $have_pk = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | my @pk_set_methods = $meta->primary_key_column_mutator_names; | |||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | my $got_last_insert_id = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | foreach my $pk (@pk_methods) | |||||||||||||||||||||||||||||||||||||||||
| 1218 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | ▶ | unless(defined $self->$pk()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1220 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | # XXX: This clause assumes that any db that uses last_insert_id | ||||||||||||||||||||||||||||||||||||||||||
| 1222 | # XXX: can only have one such id per table. This is currently | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | # XXX: true for the supported dbs: MySQL, Pg, SQLite, Informix. | ||||||||||||||||||||||||||||||||||||||||||
| 1224 | 0 | ▶ | if($got_last_insert_id) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1225 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | $have_pk = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1229 | elsif(my $pk_val = $db->last_insertid_from_sth($sth)) | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | my $set_pk = $pk_set_methods[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | $self->$set_pk($pk_val); | |||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | $got_last_insert_id = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1237 | 0 | $have_pk = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1238 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 1243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||||||||||||||||
| 1245 | 0 | $self->{STATE_IN_DB()} = $have_pk; | |||||||||||||||||||||||||||||||||||||||||
| 1246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||
| 1248 | #if($started_new_tx) | ||||||||||||||||||||||||||||||||||||||||||
| 1249 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | # $db->commit or die $db->error; | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||
| 1257 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1258 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | ▶ | $self->error(ref $error ? $error : "insert() - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1260 | #$db->rollback or warn $db->error if($started_new_tx); | ||||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 1262 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | $self->{MODIFIED_COLUMNS()} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||
| 1267 | 0 | ▶ | return $self || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self || 1
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||
| 1270 | 61 | my %CASCADE_VALUES = (delete => 'delete', null => 'null', 1 => 'delete'); | |||||||||||||||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||||||||||||||||
| 1272 | sub delete | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=51 SCAR=78.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||
| 1276 | 0 | my $meta = $self->meta; | |||||||||||||||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||||||||||||||||
| 1278 | my $prepare_cached = | ||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | ▶ | exists $args{'prepare_cached'} ? $args{'prepare_cached'} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1280 | $meta->dbi_prepare_cached; | ||||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||
| 1282 | 0 | local $self->{STATE_SAVING()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | my @pk_methods = $meta->primary_key_column_accessor_names; | |||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | my @pk_values = grep { defined } map { $self->$_() } @pk_methods; | |||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | ▶ | unless(@pk_values == @pk_methods) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1288 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | $self->error("Cannot delete " . ref($self) . " without a primary key (" . | |||||||||||||||||||||||||||||||||||||||||
| 1290 | join(', ', @pk_methods) . ')'); | ||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||
| 1295 | # Totally separate code path for cascaded delete | ||||||||||||||||||||||||||||||||||||||||||
| 1296 | 0 | ▶ | if(my $cascade = $args{'cascade'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1297 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | ▶ | unless(exists $CASCADE_VALUES{$cascade}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1299 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | Carp::croak "Illegal value for 'cascade' parameter: '$cascade'. ", | |||||||||||||||||||||||||||||||||||||||||
| 1301 | "Valid values are 'delete', 'null', and '1'"; | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||
| 1304 | 0 | $cascade = $CASCADE_VALUES{$cascade}; | |||||||||||||||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | my $mgr_error_mode = Rose::DB::Object::Manager->error_mode; | |||||||||||||||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | my($db, $started_new_tx, $error); | |||||||||||||||||||||||||||||||||||||||||
| 1309 | |||||||||||||||||||||||||||||||||||||||||||
| 1310 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||
| 1314 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 1316 | 0 | $db = $self->db; | |||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | my $meta = $self->meta; | |||||||||||||||||||||||||||||||||||||||||
| 1318 | |||||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | my $ret = $db->begin_work; | |||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||
| 1321 | 0 | ▶ | unless(defined $ret) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1322 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1323 | 0 | die 'Could not begin transaction before deleting with cascade - ', | |||||||||||||||||||||||||||||||||||||||||
| 1324 | $db->error; | ||||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | ▶ | $started_new_tx = ($ret == IN_TRANSACTION) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||
| 1329 | 0 | ▶ | unless($self->{STATE_IN_DB()}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1330 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | 0 | ▶ | $self->load | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1332 | or die "Could not load in preparation for cascading delete: ", | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | $self->error; | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | Rose::DB::Object::Manager->error_mode('fatal'); | |||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||
| 1338 | 0 | my @one_to_one_rels; | |||||||||||||||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||||||||||||||||
| 1340 | # Process all the rows for each "... to many" relationship | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | 0 | REL: foreach my $relationship ($meta->relationships) | |||||||||||||||||||||||||||||||||||||||||
| 1342 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1343 | 0 | my $rel_type = $relationship->type; | |||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | ▶ | if($rel_type eq 'one to many') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1346 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | 0 | my $column_map = $relationship->column_map; | |||||||||||||||||||||||||||||||||||||||||
| 1348 | 0 | my @query; | |||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | foreach my $local_column (keys %$column_map) | |||||||||||||||||||||||||||||||||||||||||
| 1351 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1352 | 0 | my $foreign_column = $column_map->{$local_column}; | |||||||||||||||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||||||||||||||||
| 1354 | 0 | my $method = $meta->column_accessor_method_name($local_column); | |||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | my $value = $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||
| 1357 | # XXX: Comment this out to allow null keys | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | 0 | ▶ | next REL unless(defined $value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1359 | |||||||||||||||||||||||||||||||||||||||||||
| 1360 | 0 | push(@query, $foreign_column => $value); | |||||||||||||||||||||||||||||||||||||||||
| 1361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||
| 1363 | 0 | ▶ | if($cascade eq 'delete') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1364 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | 0 | Rose::DB::Object::Manager->delete_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1366 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | object_class => $relationship->class, | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1370 | elsif($cascade eq 'null') | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1372 | 0 | my %set = map { $_ => undef } values(%$column_map); | |||||||||||||||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||||||||||||||||
| 1374 | 0 | Rose::DB::Object::Manager->update_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1375 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | object_class => $relationship->class, | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | set => \%set, | ||||||||||||||||||||||||||||||||||||||||||
| 1378 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | 0 | else { Carp::confess "Illegal cascade value '$cascade' snuck through" } | |||||||||||||||||||||||||||||||||||||||||
| 1381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | elsif($rel_type eq 'many to many') | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | 0 | my $map_class = $relationship->map_class; | |||||||||||||||||||||||||||||||||||||||||
| 1385 | 0 | my $map_from = $relationship->map_from; | |||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||
| 1387 | 0 | ▶ | my $map_from_relationship = | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$map_class->meta->foreign_key($map_from) || $map_class->meta->relationship($map_from) || Carp::confess(q[No foreign key or 'many to one' relationship ], "named '${map_from}' in class $map_class")
$map_class->meta->foreign_key($map_from) or $map_class->meta->relationship($map_from)
MC/DC0%0/2
$map_class->meta->foreign_key($map_from) || $map_class->meta->relationship($map_from) || Carp::confess(q[No foreign key or 'many to one' relationship ], "named '${map_from}' in class $map_class")
$map_class->meta->foreign_key($map_from)
$map_class->meta->relationship($map_from)
Truth table0%0/3
A or B
A= $map_class->meta->foreign_key($map_from)B= $map_class->meta->relationship($map_from)
| |||||||||||||||||||||||||||||||||||||||||||
| 1388 | $map_class->meta->foreign_key($map_from) || | ||||||||||||||||||||||||||||||||||||||||||
| 1389 | $map_class->meta->relationship($map_from) || | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | Carp::confess "No foreign key or 'many to one' relationship ", | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | "named '$map_from' in class $map_class"; | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 0 | my $key_columns = $map_from_relationship->key_columns; | |||||||||||||||||||||||||||||||||||||||||
| 1394 | 0 | my @query; | |||||||||||||||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||||||||||||||||
| 1396 | # "Local" here means "local to the mapping table" | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | 0 | foreach my $local_column (keys %$key_columns) | |||||||||||||||||||||||||||||||||||||||||
| 1398 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | 0 | my $foreign_column = $key_columns->{$local_column}; | |||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||
| 1401 | 0 | my $method = $meta->column_accessor_method_name($foreign_column); | |||||||||||||||||||||||||||||||||||||||||
| 1402 | 0 | my $value = $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||
| 1404 | # XXX: Comment this out to allow null keys | ||||||||||||||||||||||||||||||||||||||||||
| 1405 | 0 | ▶ | next REL unless(defined $value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||
| 1407 | 0 | push(@query, $local_column => $value); | |||||||||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | ▶ | if($cascade eq 'delete') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1411 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | 0 | Rose::DB::Object::Manager->delete_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1413 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | object_class => $map_class, | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1417 | elsif($cascade eq 'null') | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1419 | 0 | my %set = map { $_ => undef } keys(%$key_columns); | |||||||||||||||||||||||||||||||||||||||||
| 1420 | |||||||||||||||||||||||||||||||||||||||||||
| 1421 | 0 | Rose::DB::Object::Manager->update_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1422 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | object_class => $map_class, | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | set => \%set, | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | 0 | else { Carp::confess "Illegal cascade value '$cascade' snuck through" } | |||||||||||||||||||||||||||||||||||||||||
| 1428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1429 | elsif($rel_type eq 'one to one') | ||||||||||||||||||||||||||||||||||||||||||
| 1430 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | 0 | push(@one_to_one_rels, $relationship); | |||||||||||||||||||||||||||||||||||||||||
| 1432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||||||||||||||||
| 1435 | # Delete the object itself | ||||||||||||||||||||||||||||||||||||||||||
| 1436 | 0 | ▶ | my $dbh = $db->dbh or die "Could not get dbh: ", $self->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1437 | #local $self->{STATE_SAVING()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 1438 | 0 | local $dbh->{'RaiseError'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||
| 1440 | # $meta->prepare_delete_options (defunct) | ||||||||||||||||||||||||||||||||||||||||||
| 1441 | 0 | ▶ | my $sth = $prepare_cached ? $dbh->prepare_cached($meta->delete_sql($db), undef, 3) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1442 | $dbh->prepare($meta->delete_sql($db)); | ||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||
| 1444 | 0 | ▶ | $Debug && warn $meta->delete_sql($db), " - bind params: ", join(', ', @pk_values), "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1445 | 0 | $sth->execute(@pk_values); | |||||||||||||||||||||||||||||||||||||||||
| 1446 | |||||||||||||||||||||||||||||||||||||||||||
| 1447 | 0 | ▶ | unless($sth->rows > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1448 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | 0 | $self->error("Did not delete " . ref($self) . ' where ' . | |||||||||||||||||||||||||||||||||||||||||
| 1450 | join(', ', @pk_methods) . ' = ' . join(', ', @pk_values)); | ||||||||||||||||||||||||||||||||||||||||||
| 1451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||
| 1453 | # Process all rows referred to by "one to one" foreign keys | ||||||||||||||||||||||||||||||||||||||||||
| 1454 | 0 | FK: foreach my $fk ($meta->foreign_keys) | |||||||||||||||||||||||||||||||||||||||||
| 1455 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | 0 | ▶ | next unless($fk->relationship_type eq 'one to one'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1457 | |||||||||||||||||||||||||||||||||||||||||||
| 1458 | 0 | my $key_columns = $fk->key_columns; | |||||||||||||||||||||||||||||||||||||||||
| 1459 | 0 | my @query; | |||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||
| 1461 | 0 | foreach my $local_column (keys %$key_columns) | |||||||||||||||||||||||||||||||||||||||||
| 1462 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | 0 | my $foreign_column = $key_columns->{$local_column}; | |||||||||||||||||||||||||||||||||||||||||
| 1464 | |||||||||||||||||||||||||||||||||||||||||||
| 1465 | 0 | my $method = $meta->column_accessor_method_name($local_column); | |||||||||||||||||||||||||||||||||||||||||
| 1466 | 0 | my $value = $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||
| 1468 | # XXX: Comment this out to allow null keys | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | 0 | ▶ | next FK unless(defined $value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1470 | |||||||||||||||||||||||||||||||||||||||||||
| 1471 | 0 | push(@query, $foreign_column => $value); | |||||||||||||||||||||||||||||||||||||||||
| 1472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||||||||||||||||
| 1474 | 0 | ▶ | if($cascade eq 'delete') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1475 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1476 | 0 | Rose::DB::Object::Manager->delete_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1477 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | object_class => $fk->class, | ||||||||||||||||||||||||||||||||||||||||||
| 1479 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1481 | elsif($cascade eq 'null') | ||||||||||||||||||||||||||||||||||||||||||
| 1482 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1483 | 0 | my %set = map { $_ => undef } values(%$key_columns); | |||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||
| 1485 | 0 | Rose::DB::Object::Manager->update_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1486 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1487 | object_class => $fk->class, | ||||||||||||||||||||||||||||||||||||||||||
| 1488 | set => \%set, | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1491 | 0 | else { Carp::confess "Illegal cascade value '$cascade' snuck through" } | |||||||||||||||||||||||||||||||||||||||||
| 1492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||
| 1494 | # Process all the rows for each "one to one" relationship | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | 0 | REL: foreach my $relationship (@one_to_one_rels) | |||||||||||||||||||||||||||||||||||||||||
| 1496 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | 0 | my $column_map = $relationship->column_map; | |||||||||||||||||||||||||||||||||||||||||
| 1498 | 0 | my @query; | |||||||||||||||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||||||||||||||||
| 1500 | 0 | foreach my $local_column (keys %$column_map) | |||||||||||||||||||||||||||||||||||||||||
| 1501 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1502 | 0 | my $foreign_column = $column_map->{$local_column}; | |||||||||||||||||||||||||||||||||||||||||
| 1503 | |||||||||||||||||||||||||||||||||||||||||||
| 1504 | 0 | my $method = $meta->column_accessor_method_name($local_column); | |||||||||||||||||||||||||||||||||||||||||
| 1505 | 0 | my $value = $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||||||||||||||||
| 1507 | # XXX: Comment this out to allow null keys | ||||||||||||||||||||||||||||||||||||||||||
| 1508 | 0 | ▶ | next REL unless(defined $value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1509 | |||||||||||||||||||||||||||||||||||||||||||
| 1510 | 0 | push(@query, $foreign_column => $value); | |||||||||||||||||||||||||||||||||||||||||
| 1511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||||||||||||||||
| 1513 | 0 | ▶ | if($cascade eq 'delete') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1514 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1515 | 0 | Rose::DB::Object::Manager->delete_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1516 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1517 | object_class => $relationship->class, | ||||||||||||||||||||||||||||||||||||||||||
| 1518 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1520 | elsif($cascade eq 'null') | ||||||||||||||||||||||||||||||||||||||||||
| 1521 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1522 | 0 | my %set = map { $_ => undef } values(%$column_map); | |||||||||||||||||||||||||||||||||||||||||
| 1523 | |||||||||||||||||||||||||||||||||||||||||||
| 1524 | 0 | Rose::DB::Object::Manager->update_objects( | |||||||||||||||||||||||||||||||||||||||||
| 1525 | db => $db, | ||||||||||||||||||||||||||||||||||||||||||
| 1526 | object_class => $relationship->class, | ||||||||||||||||||||||||||||||||||||||||||
| 1527 | set => \%set, | ||||||||||||||||||||||||||||||||||||||||||
| 1528 | where => \@query); | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1530 | 0 | else { Carp::confess "Illegal cascade value '$cascade' snuck through" } | |||||||||||||||||||||||||||||||||||||||||
| 1531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||||||||||||||||
| 1533 | 0 | ▶ | if($started_new_tx) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1534 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1535 | 0 | ▶ | $db->commit or die $db->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1537 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||
| 1539 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 1540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | |||||||||||||||||||||||||||||||||||||||||||
| 1542 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1543 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1544 | 0 | Rose::DB::Object::Manager->error_mode($mgr_error_mode); | |||||||||||||||||||||||||||||||||||||||||
| 1545 | 0 | ▶ | $self->error(ref $error ? $error : "delete() with cascade - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1546 | 0 | ▶ | $db->rollback if($db && $started_new_tx); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$db and $started_new_tx
MC/DC0%0/2
$db and $started_new_tx
$db
$started_new_tx
Truth table0%0/3
A and B
A= $dbB= $started_new_tx
| |||||||||||||||||||||||||||||||||||||||||||
| 1547 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 1548 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1550 | |||||||||||||||||||||||||||||||||||||||||||
| 1551 | 0 | Rose::DB::Object::Manager->error_mode($mgr_error_mode); | |||||||||||||||||||||||||||||||||||||||||
| 1552 | 0 | $self->{STATE_IN_DB()} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1553 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | else | ||||||||||||||||||||||||||||||||||||||||||
| 1556 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1557 | 0 | ▶ | my $db = $self->db or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1558 | 0 | ▶ | my $dbh = $db->dbh or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1559 | |||||||||||||||||||||||||||||||||||||||||||
| 1560 | 0 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||
| 1562 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1564 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||||||||||||||||
| 1566 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 1568 | #local $self->{STATE_SAVING()} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | 0 | local $dbh->{'RaiseError'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||||||||||||||||
| 1571 | # $meta->prepare_delete_options (defunct) | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | 0 | ▶ | my $sth = $prepare_cached ? $dbh->prepare_cached($meta->delete_sql($db), undef, 3) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1573 | $dbh->prepare($meta->delete_sql($db)); | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | |||||||||||||||||||||||||||||||||||||||||||
| 1575 | 0 | ▶ | $Debug && warn $meta->delete_sql($db), " - bind params: ", join(', ', @pk_values), "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1576 | 0 | $sth->execute(@pk_values); | |||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||
| 1578 | 0 | ▶ | unless($sth->rows > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1579 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1580 | 0 | $self->error("Did not delete " . ref($self) . ' where ' . | |||||||||||||||||||||||||||||||||||||||||
| 1581 | join(', ', @pk_methods) . ' = ' . join(', ', @pk_values)); | ||||||||||||||||||||||||||||||||||||||||||
| 1582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1583 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||||||||||||||||
| 1585 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 1586 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1587 | |||||||||||||||||||||||||||||||||||||||||||
| 1588 | 0 | ▶ | if($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1589 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1590 | 0 | ▶ | $self->error(ref $error ? $error : "delete() - $error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1591 | 0 | $self->meta->handle_error($self); | |||||||||||||||||||||||||||||||||||||||||
| 1592 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||
| 1595 | 0 | $self->{STATE_IN_DB()} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1596 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1599 | |||||||||||||||||||||||||||||||||||||||||||
| 1600 | 61 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 1601 | |||||||||||||||||||||||||||||||||||||||||||
| 1602 | sub AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||
| 1603 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1604 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1605 | |||||||||||||||||||||||||||||||||||||||||||
| 1606 | 0 | my $msg = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||||||||||||||||
| 1608 | TRY: | ||||||||||||||||||||||||||||||||||||||||||
| 1609 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1610 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 1611 | |||||||||||||||||||||||||||||||||||||||||||
| 1612 | # Not sure if this will ever be used, but just in case... | ||||||||||||||||||||||||||||||||||||||||||
| 1613 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 1614 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 1615 | 0 | my @fks = $self->meta->deferred_foreign_keys; | |||||||||||||||||||||||||||||||||||||||||
| 1616 | 0 | my @rels = $self->meta->deferred_relationships; | |||||||||||||||||||||||||||||||||||||||||
| 1617 | |||||||||||||||||||||||||||||||||||||||||||
| 1618 | 0 | ▶ | if(@fks || @rels) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@fks or @rels
MC/DC0%0/2
@fks or @rels
@fks
@rels
Truth table0%0/3
A or B
A= @fksB= @rels
| |||||||||||||||||||||||||||||||||||||||||||
| 1619 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1620 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 1621 | |||||||||||||||||||||||||||||||||||||||||||
| 1622 | 0 | my $tmp_msg =<<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 1623 | Methods for the following relationships and foreign keys were deferred and | ||||||||||||||||||||||||||||||||||||||||||
| 1624 | then never actually created in the class $class. | ||||||||||||||||||||||||||||||||||||||||||
| 1625 | |||||||||||||||||||||||||||||||||||||||||||
| 1626 | TYPE NAME | ||||||||||||||||||||||||||||||||||||||||||
| 1627 | ---- ---- | ||||||||||||||||||||||||||||||||||||||||||
| 1628 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 1629 | |||||||||||||||||||||||||||||||||||||||||||
| 1630 | 0 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1631 | |||||||||||||||||||||||||||||||||||||||||||
| 1632 | 0 | foreach my $thing (@fks, @rels) | |||||||||||||||||||||||||||||||||||||||||
| 1633 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1634 | 0 | ▶ | next unless($thing->parent->class eq $class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||||||||||||||||
| 1636 | 0 | $found++; | |||||||||||||||||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||||||||||||||||
| 1638 | 0 | ▶ | my $type = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1639 | $thing->isa('Rose::DB::Object::Metadata::Relationship') ? 'Relationship' : | ||||||||||||||||||||||||||||||||||||||||||
| 1640 | $thing->isa('Rose::DB::Object::Metadata::ForeignKey') ? 'Foreign Key' : | ||||||||||||||||||||||||||||||||||||||||||
| 1641 | '???'; | ||||||||||||||||||||||||||||||||||||||||||
| 1642 | |||||||||||||||||||||||||||||||||||||||||||
| 1643 | 0 | $tmp_msg .= sprintf("%-15s %s\n", $type, $thing->name); | |||||||||||||||||||||||||||||||||||||||||
| 1644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | |||||||||||||||||||||||||||||||||||||||||||
| 1646 | 0 | ▶ | $msg = "\n\n$tmp_msg\n" if($tmp_msg && $found); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tmp_msg and $found
MC/DC0%0/2
$tmp_msg and $found
$tmp_msg
$found
Truth table0%0/3
A and B
A= $tmp_msgB= $found
| |||||||||||||||||||||||||||||||||||||||||||
| 1647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1648 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1649 | |||||||||||||||||||||||||||||||||||||||||||
| 1650 | # XXX: Ignoring errors | ||||||||||||||||||||||||||||||||||||||||||
| 1651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1652 | |||||||||||||||||||||||||||||||||||||||||||
| 1653 | 0 | ▶ | my $method_type = ref $self ? 'object' : 'class'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1654 | |||||||||||||||||||||||||||||||||||||||||||
| 1655 | 0 | ▶ | if($AUTOLOAD =~ /^(.+)::(.+)$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1656 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1657 | 0 | Carp::confess qq(Can't locate $method_type method "$2" via package "$1"$msg); | |||||||||||||||||||||||||||||||||||||||||
| 1658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1659 | else # not reached? | ||||||||||||||||||||||||||||||||||||||||||
| 1660 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1661 | 0 | Carp::confess qq(Can't locate $method_type method $AUTOLOAD$msg); | |||||||||||||||||||||||||||||||||||||||||
| 1662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1664 | |||||||||||||||||||||||||||||||||||||||||||
| 1665 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1666 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 1667 | # my($self) = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 1668 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1669 | # if($self->{FLAG_DB_IS_PRIVATE()}) | ||||||||||||||||||||||||||||||||||||||||||
| 1670 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 1671 | # if(my $db = $self->{'db'}) | ||||||||||||||||||||||||||||||||||||||||||
| 1672 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 1673 | # #$Debug && warn "$self DISCONNECT\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1674 | # $db->disconnect; | ||||||||||||||||||||||||||||||||||||||||||
| 1675 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 1676 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 1677 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 1678 | |||||||||||||||||||||||||||||||||||||||||||
| 1679 | 61 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1680 | |||||||||||||||||||||||||||||||||||||||||||
| 1681 | __END__ | ||||||||||||||||||||||||||||||||||||||||||