| 1 | package SQL::Composer::Upsert; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | 3 | ▶ | use SQL::Composer::Insert; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | 3 | ▶ | our @ISA; BEGIN { @ISA = ('SQL::Composer::Insert') }; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | sub new { | ||||||||||||||||||
| 11 | 3 | ▶ | my $class = shift; | ||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||
| 12 | 3 | my (%params) = @_; | |||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | my $driver = $params{driver} | ||||||||||||||||||
| 15 | 3 | ▶ | || die 'Cannot create an Upsert object without specifying a `driver`'; | ||||||||||||||||
|
Condition50%1/2
$params{'driver'} || die('Cannot create an Upsert object without specifying a `driver`')
MC/DC0%0/1
$params{'driver'} || die('Cannot create an Upsert object without specifying a `driver`')
$params{'driver'}
Truth table50%1/2
A
A= $params{'driver'}
| |||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | 3 | my $self = $class->SUPER::new( %params ); | |||||||||||||||||
| 18 | 3 | my $sql = $self->{sql}; | |||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 3 | ▶ | if ($driver =~ m/sqlite/i) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 21 | 1 | $sql =~ s/^INSERT /INSERT OR REPLACE /; | |||||||||||||||||
| 22 | } | ||||||||||||||||||
| 23 | elsif ($driver =~ m/mysql/i) { | ||||||||||||||||||
| 24 | $sql .= ' ON DUPLICATE KEY UPDATE ' | ||||||||||||||||||
| 25 | . (join ', ' => map { | ||||||||||||||||||
| 26 | 2 | my $c = $self->_quote($_); | |||||||||||||||||
| 27 | 2 | ($c.' = VALUES('.$c.')') | |||||||||||||||||
| 28 | 1 | } @{ $self->{columns} }); | |||||||||||||||||
| 29 | } | ||||||||||||||||||
| 30 | elsif ($driver =~ m/pg/i) { | ||||||||||||||||||
| 31 | 1 | $sql .= ' ON CONFLICT DO UPDATE' | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | else { | ||||||||||||||||||
| 34 | 0 | die 'The Upsert `driver` (' . $driver . ') is not supported'; | |||||||||||||||||
| 35 | } | ||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | 3 | $self->{sql} = $sql; | |||||||||||||||||
| 38 | |||||||||||||||||||
| 39 | 3 | return $self; | |||||||||||||||||
| 40 | } | ||||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | 3 | 1; | |||||||||||||||||
| 43 | __END__ | ||||||||||||||||||