line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::ORM::Declarative::JRow; |
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
121
|
|
3
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
78
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1468
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
@ISA = qw(DBIx::ORM::Declarative::Row); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub delete |
10
|
|
|
|
|
|
|
{ |
11
|
0
|
|
|
0
|
1
|
|
carp "You must delete each component of a join individually"; |
12
|
0
|
|
|
|
|
|
return; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Create a collection of where clause to find this particular join object |
16
|
|
|
|
|
|
|
sub __create_where |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
19
|
0
|
0
|
0
|
|
|
|
carp "not a class method" and return unless ref $self; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Assemble the information, if we haven't already |
22
|
0
|
0
|
|
|
|
|
if(not exists $self->{__whereinfo}) |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
# We'll work on these tables... |
25
|
0
|
|
|
|
|
|
for my $table ($self->_primary, map { $_->{table} } $self->_join_info) |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
|
|
|
my $tab_obj = $self->table($table); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Get a list of keys to use |
30
|
0
|
|
|
|
|
|
my ($un) = $tab_obj->_unique_keys; |
31
|
0
|
|
0
|
|
|
|
$un ||= [ map { $_->{name} } $tab_obj->_columns ]; |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my %name2sql_map = $tab_obj->_column_map; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Get the data and keys |
35
|
0
|
|
|
|
|
|
my (@wclause, @binds); |
36
|
0
|
|
|
|
|
|
for my $key (@$un) |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
|
|
|
|
|
my $sql_name = $name2sql_map{$key}; |
39
|
0
|
|
|
|
|
|
my $value = $self->{__data}{"$table.$sql_name"}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Create the subclause |
42
|
0
|
0
|
|
|
|
|
if(defined $value) |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
|
push @wclause, "$sql_name=?"; |
45
|
0
|
|
|
|
|
|
push @binds, $value; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
|
|
|
|
push @wclause, "$sql_name IS NULL"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Paste it all together |
54
|
0
|
|
|
|
|
|
@{$self->{__whereinfo}{$table}} = |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# The WHERE clause the data |
56
|
|
|
|
|
|
|
(join(' AND ', @wclause), @binds); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return %{$self->{__whereinfo}}; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub commit |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
66
|
0
|
0
|
0
|
|
|
|
carp "commit: not a class method" and return unless ref $self; |
67
|
0
|
0
|
|
|
|
|
return $self unless $self->{__dirty}; |
68
|
0
|
|
|
|
|
|
my $handle = $self->handle; |
69
|
0
|
0
|
0
|
|
|
|
carp "Can't commit without a handle" and return unless $handle; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Give it the business... |
72
|
0
|
|
|
|
|
|
my %whereinfo = $self->__create_where; |
73
|
0
|
|
|
|
|
|
for my $table (keys %whereinfo) |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
# Gather our data |
76
|
0
|
|
|
|
|
|
my $tab_obj = $self->table($table); |
77
|
0
|
|
|
|
|
|
my @cols= map { $_->{sql_name} } $tab_obj->_columns; |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Silly as it may be, a table with no columns is still "legal" |
80
|
0
|
0
|
0
|
|
|
|
carp "encountered a table with no columns" and next unless @cols; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my ($wclause, @binds) = @{$whereinfo{$table}}; |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
unshift @binds, @{$self->{__data}}{map { "$table.$_" } @cols}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# The SQL statement |
86
|
0
|
|
|
|
|
|
my $table_name = $tab_obj->_sql_name; |
87
|
0
|
|
|
|
|
|
my $sql = "UPDATE $table_name SET " |
88
|
0
|
|
|
|
|
|
. join(',', map { "$_=?" } @cols) . " WHERE $wclause"; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if(not $handle->do($sql, undef, @binds)) |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
|
|
|
carp "Database error: ", $handle->errstr; |
93
|
0
|
|
|
|
|
|
$self->__do_rollback; |
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
delete $self->{__dirty}; |
99
|
0
|
|
|
|
|
|
return $self; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
__END__ |