addPostalAddress: additional argument to set date_encountered

This commit is contained in:
Bradley M. Kuhn 2021-02-11 11:57:36 -08:00
parent 9a54b77881
commit 16ce9f4bf1

View file

@ -703,14 +703,20 @@ Arguments:
Scalar string that contains the address type. This type will be created in
the database if it does not already exist, so be careful.
=item $date (optional)
Scalar string in the format of YYYY-MM-DD, and will be set to the
date_encountered for the record if provided. If not provided, the
date_encountered will be today.
=back
Returns the id value of the postal_address table entry.
=cut
sub addPostalAddress($$$$) {
my($self, $id, $formattedPostalAddress, $addressType) = @_;
sub addPostalAddress($$$$;$) {
my($self, $id, $formattedPostalAddress, $addressType, $dateEncountered) = @_;
die "addPostalAddress: invalid id, $id" unless $self->_verifyId($id);
die "addPostalAddress: the formatted postal address must be defined"
@ -728,10 +734,18 @@ sub addPostalAddress($$$$) {
$self->_rollback();
die $@ if $@;
}
my $sth = $self->dbh->prepare("INSERT INTO postal_address(formatted_address, type_id, date_encountered)" .
"VALUES( ?, ?, date('now'))");
my $insertStr = "INSERT INTO postal_address(formatted_address, type_id, date_encountered)" .
"VALUES( ?, ?, ";
my $sth;
if (defined $dateEncountered) {
$insertStr .= "?)";
$sth = $self->dbh->prepare($insertStr);
$sth->execute($formattedPostalAddress, $addressTypeId, $dateEncountered);
} else {
$insertStr .= "date('now'))";
$sth = $self->dbh->prepare($insertStr);
$sth->execute($formattedPostalAddress, $addressTypeId);
}
my $addressId = $self->dbh->last_insert_id("","","","");
$sth->finish();