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