for my $row ( sort keys %devueltos ) {
$query = undef;
$queryColumns = undef;
$queryValues = undef;
if ( exists( $campanas{ $devueltos{$row}{'campanaid'} } ) ) {
$campanas{ $devueltos{$row}{'campanaid'} }{'count'}++;
$campanas{ $devueltos{$row}{'campanaid'} }{'adminid'} = $devueltos{$row}{'adminid'};
}
else {
$campanas{ $devueltos{$row}{'campanaid'} }{'count'} = 1;
$campanas{ $devueltos{$row}{'campanaid'} }{'adminid'} = $devueltos{$row}{'adminid'};
}
if ( defined $devueltos{$row}{'smtpcode'} ) {
$queryColumns .= "smtpcode1, ";
$queryValues .= " '" . $devueltos{$row}{'smtpcode'} . "', ";
}
if ( defined $devueltos{$row}{'email'} ) {
$queryColumns .= "email, ";
$queryValues .= " '" . $devueltos{$row}{'email'} . "', ";
}
if ( defined $devueltos{$row}{'smtpaction'} ) {
$queryColumns .= "smtpaction, ";
$queryValues .= " '" . $devueltos{$row}{'smtpaction'} . "', ";
}
if ( defined $devueltos{$row}{'smtpstatus'} ) {
$queryColumns .= "smtpcode, ";
$queryValues .= " '" . $devueltos{$row}{'smtpstatus'} . "', ";
}
if ( defined $devueltos{$row}{'smtpdiagnosticcode'} ) {
my $deletechar = $devueltos{$row}{'smtpdiagnosticcode'} =~ s/'//g;
$queryColumns .= "smtpprefixdetail, ";
#$queryValues .= " E'".encode('utf8', decode('iso-8859-1', $devueltos{$row}{'smtpdiagnosticcode'}))."', ";
$queryValues .= " '" . encode( 'utf8', decode( 'iso-8859-1', $deletechar ) ) . "', ";
}
if ( defined $devueltos{$row}{'smtpremotemta'} ) {
$queryColumns .= "smtpremote, ";
$queryValues .= " '" . $devueltos{$row}{'smtpremotemta'} . "', ";
}
if ( defined $devueltos{$row}{'smtplastattempdate'} ) {
$queryColumns .= "smtpdate, ";
$queryValues .= " '" . $devueltos{$row}{'smtplastattempdate'} . "', ";
}
if ( defined $devueltos{$row}{'userid'} ) {
$queryColumns .= "id_usuario, ";
$queryValues .= "$devueltos{$row}{'userid'}, ";
}
if ( defined $devueltos{$row}{'adminid'} ) {
$queryColumns .= "id_admin, ";
$queryValues .= "$devueltos{$row}{'adminid'}, ";
}
if ( defined $devueltos{$row}{'campanaid'} ) {
$queryColumns .= "id_campana, ";
$queryValues .= "$devueltos{$row}{'campanaid'}, ";
}
if ( defined $devueltos{$row}{'listaid'} ) {
$queryColumns .= "id_lista, ";
$queryValues .= "$devueltos{$row}{'listaid'}, ";
}
if ( defined $devueltos{$row}{'status'} ) {
$queryColumns .= "status, ";
$queryValues .= "true, ";
}
$queryColumns .= "fecha ";
$queryValues .= "now() ";
$query = "INSERT INTO ex_tbl_devueltos ($queryColumns) VALUES ($queryValues);";
$string .= $query . "\n";
$sth = $dbh->prepare($query) or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";
$sth->execute() or die "Can't execute SQL statement: ", $sth->errstr(), "\n";
}