From: Don Armstrong Date: Wed, 8 Mar 2017 03:02:29 +0000 (-0800) Subject: automatically handle being passed an address to Correspondent X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=16a37f47a7d1d0d802ac73973de0e652270b882f;p=debbugs.git automatically handle being passed an address to Correspondent --- diff --git a/Debbugs/DB/ResultSet/Correspondent.pm b/Debbugs/DB/ResultSet/Correspondent.pm index 7638a52..d722a5f 100644 --- a/Debbugs/DB/ResultSet/Correspondent.pm +++ b/Debbugs/DB/ResultSet/Correspondent.pm @@ -28,16 +28,22 @@ use Debbugs::DB::Util qw(select_one); use Debbugs::Common qw(getparsedaddrs); use Debbugs::DB::Util qw(select_one); +use Scalar::Util qw(blessed); sub get_correspondent_id { my ($self,$addr) = @_; my $full_name; - if ($addr =~ /phrase(); + $addr = $addr->address(); + } elsif ($addr =~ /phrase(); + $addr = $addr->address(); + } + if (defined $full_name) { $full_name =~ s/^\"|\"$//g; $full_name =~ s/^\s+|\s+$//g; - $addr = $addr->address(); } my $rs = $self-> @@ -61,16 +67,16 @@ UNION ALL SELECT id FROM correspondent WHERE addr = ? LIMIT 1; SQL - select_one($dbh,<<'SQL',$ci,$full_name,$ci,$full_name); + if (defined $full_name) { + select_one($dbh,<<'SQL',$ci,$full_name); WITH ins AS ( INSERT INTO correspondent_full_name (correspondent,full_name) - VALUES (?,?) ON CONFLICT (correspondent,full_name) DO NOTHING RETURNING id -) -SELECT id FROM ins + VALUES (?,?) ON CONFLICT (correspondent,full_name) DO NOTHING RETURNING 1 +) SELECT 1 FROM ins UNION ALL -SELECT id FROM correspondent_full_name WHERE correspondent=? AND full_name = ? -LIMIT 1; +SELECT 1; SQL + } return $ci; }, $addr,