1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| logInfo("Debut de la sequence d'insertion des donnees");
open(IGECA, "./tmp/$igecaFileName") || termine(-1); #Améliorer le log pour l'erreur
@IGECA_IN = <IGECA>;
$line_nb = 0;
$nb_ok = 0;
$nb_ko = 0;
$erreurs_nb = 0;
foreach $line (@IGECA_IN) {
chomp($line);
@champ = split(/;/, $line);
#La première ligne contient les noms des colonnes
if($line_nb > 0) {
# Il faut vérifier si nous avons bien le bon nombre de champs (5 minimum)
if(@champ >= 5) {
$ndCommande = trim(@champ[0]);
#Le ND peut être soit à 9 chiffres soit à 10 chiffres, on l'étend systématiquement à 10 chiffres en ajoutant un 0 si besoin au début
if(length($ndCommande) < 10) { $ndCommande = "0$ndCommande"; }
$dateEnvoi = trim(@champ[4]);
$chronoCommande = trim(@champ[3]);
$dateBss = trim(@champ[2]);
my $requete = q{UPDATE INTERNET_SEC_COMMANDE SET CHRONO_COMMANDE=?, DATE_ENVOI=to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
EMPLACEMENT_COMMANDE='IGECA' WHERE ND_COMMANDE=? AND DATE_BSS=to_date(?, 'YYYY-MM-DD HH24:MI:SS')};
# logInfo("Requete d'update : $requete");
logInfo("ndCommande=$ndCommande");
if($dbmod) {
$db->begin_work;
my $sth = $db->prepare($requete);
eval {
$sth->bind_param(1, $chronoCommande, { ora_type => ORA_CHAR });
$sth->bind_param(2, $dateEnvoi, { ora_type => ORA_CHAR });
$sth->bind_param(3, $ndCommande, { ora_type => ORA_CHAR });
$sth->bind_param(4, $dateBss, { ora_type => ORA_CHAR });
#$sth->execute(@$_) foreach (@updates) or print "Erreur : $DBI::errstr\n";
$sth->execute();
};
if( $@ ) {
$db->rollback;
logErreur("Une erreur s'est produite lors de l'execution de la requete pour ndCommande=$ndCommande");
$db->errstr;
} else {
$db->commit;
#print "ndCommande : $ndCommande";
}
if($sth->rows() > 0) { $nb_ok++; } else { $nb_ko++; }
$sth->finish();
}
} else { # La ligne était mal formatée, on reporte
logErreur("La ligne était mal formatée : $line");
$erreurs_nb++;
}
}
$line_nb++; |
Partager