line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Composer::Upsert; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
13330
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
66
|
|
4
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
64
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
11
|
use base 'SQL::Composer::Insert'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
442
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
22
|
use SQL::Composer::Insert; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
511
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
3
|
|
|
3
|
0
|
4948
|
my $class = shift; |
12
|
3
|
|
|
|
|
14
|
my (%params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $driver = $params{driver} |
15
|
3
|
|
50
|
|
|
10
|
|| die 'Cannot create an Upsert object without specifying a `driver`'; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
19
|
my $self = $class->SUPER::new(%params); |
18
|
3
|
|
|
|
|
8
|
my $sql = $self->{sql}; |
19
|
|
|
|
|
|
|
|
20
|
3
|
100
|
|
|
|
16
|
if ($driver =~ m/sqlite/i) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21
|
1
|
|
|
|
|
5
|
$sql =~ s/^INSERT /INSERT OR REPLACE /; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
elsif ($driver =~ m/mysql/i) { |
24
|
|
|
|
|
|
|
$sql .= ' ON DUPLICATE KEY UPDATE ' . ( |
25
|
|
|
|
|
|
|
join ', ' => map { |
26
|
2
|
|
|
|
|
6
|
my $c = $self->_quote($_); |
27
|
2
|
|
|
|
|
8
|
($c . ' = VALUES(' . $c . ')') |
28
|
1
|
|
|
|
|
3
|
} @{$self->{columns}} |
|
1
|
|
|
|
|
3
|
|
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($driver =~ m/pg/i) { |
32
|
1
|
|
|
|
|
3
|
$sql .= ' ON CONFLICT DO UPDATE'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
0
|
|
|
|
|
0
|
die 'The Upsert `driver` (' . $driver . ') is not supported'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
7
|
$self->{sql} = $sql; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
9
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
__END__ |