line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Teng::Plugin::Replace; |
2
|
1
|
|
|
1
|
|
703
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
3
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
9
|
use utf8; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/replace/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub replace { |
9
|
1
|
|
|
1
|
1
|
4
|
my ($self, $table_name, $args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
4
|
my $table = $self->schema->get_table($table_name); |
12
|
1
|
50
|
|
|
|
4
|
if (! $table) { |
13
|
0
|
|
|
|
|
0
|
Carp::croak( "Table definition for $table_name does not exist (Did you declare it in our schema?)" ); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
2
|
for my $col (keys %{$args}) { |
|
1
|
|
|
|
|
3
|
|
17
|
2
|
|
|
|
|
6
|
$args->{$col} = $table->call_deflate($col, $args->{$col}); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
4
|
my ($sql, @binds) = $self->sql_builder->insert( $table_name, $args, { prefix => 'REPLACE INTO' } ); |
21
|
1
|
|
|
|
|
121
|
$self->execute($sql, \@binds, $table_name); |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
4
|
my $pk = $table->primary_keys(); |
24
|
1
|
50
|
33
|
|
|
11
|
if (scalar(@$pk) == 1 && not defined $args->{$pk->[0]}) { |
25
|
0
|
|
|
|
|
0
|
$args->{$pk->[0]} = $self->_last_insert_id($table_name); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
3
|
return $args if $self->suppress_row_objects; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
$table->row_class->new( |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
row_data => $args, |
33
|
|
|
|
|
|
|
teng => $self, |
34
|
|
|
|
|
|
|
table_name => $table_name, |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
__END__ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Teng::Plugin::Replace - Add replace for Teng |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 4 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item C<< $teng->replace($table_name, \%rows_data) >> |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
record by replace. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
example: |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Your::Model->replace('user', |
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
id => 3, |
59
|
|
|
|
|
|
|
name => 'walf443', |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=back |
64
|
|
|
|
|
|
|
|