@rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT \perl\bin\perl -x -S %0 %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo L\'interpréteur Perl n\'existe pas dans votre PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto endofperl @rem '; #!/usr/bin/perl -w #line 15 use strict; use DBI; my $dbh = connecterBaseDonnees(); # # Preparation des SQL d'insertion # my $insertOccitan = "INSERT INTO motOccitan (mot) values (?)"; my $insertOccitanSth = $dbh->prepare($insertOccitan) or die "impossible de préparer la requête $insertOccitan\n"; my $insertCatalan = "INSERT INTO motCatalan (mot) values (?)"; my $insertCatalanSth = $dbh->prepare($insertCatalan) or die "impossible de préparer la requête $insertCatalan\n"; my $insertFrancais= "INSERT INTO motFrancais (mot) values (?)"; my $insertFrancaisSth = $dbh->prepare($insertFrancais) or die "impossible de préparer la requête $insertFrancais\n"; my $insertAnglais = "INSERT INTO motAnglais (mot) values (?)"; my $insertAnglaisSth = $dbh->prepare($insertAnglais) or die "impossible de préparer la requête $insertAnglais\n"; my $insertTraduction = "INSERT INTO r_traduction (idMot1,lang1, idMot2, lang2) values (?,?,?,? )"; my $insertTraductionSth = $dbh->prepare($insertTraduction) or die "impossible de préparer la requête $insertTraduction\n"; my $queryOccitan = "SELECT max(idMotoccitan) FROM motOccitan"; my $queryOccitanSth = $dbh->prepare($queryOccitan) or die "impossible de préparer la requête $queryOccitan\n"; my $queryCatalan = "SELECT max(idMotCatalan) FROM motCatalan"; my $queryCatalanSth = $dbh->prepare($queryCatalan) or die "impossible de préparer la requête $queryCatalan\n"; my $queryFrancais = "SELECT max(idMotFrancais) FROM motFrancais"; my $queryFrancaisSth = $dbh->prepare($queryFrancais) or die "impossible de préparer la requête $queryFrancais\n"; my $queryAnglais = "SELECT max(idMotAnglais) FROM motAnglais"; my $queryAnglaisSth = $dbh->prepare($queryAnglais) or die "impossible de préparer la requête $queryAnglais\n"; # # ouverture du fichier # my $fileName = "lexic.csv"; open FH ,"<$fileName" or die("Impossible d'ouvrir le fichier «$fileName»."); # # boucle de traitement # while (){ chop; #"~occitan~ parentèsis fins a: alinèa","~catalan~","~anglés~","~francés~","~italian~" my ($occitan, $catalan, $angles, $frances) = split(',', $_); #creation du tableau d'ID my @ids = (-1,-1,-1,-1); my @codelangs = ('fr_OC','es_CA','en_EN','fr_FR'); do { # levats los gilhemets $occitan =~ s/\"//g; # protège les apostrophes en les redoublant $occitan =~ s/\'/\'\'/g; print "$occitan\t"; $insertOccitanSth->execute($occitan); $queryOccitanSth->execute; ($ids[0]) = $queryOccitanSth->fetchrow_array; print $ids[0],"\n"; } if (defined $occitan and length($occitan) > 0); # s'il n'y a pas de mot occitan ce n'est pas la peine de l'insérer if ($ids[0] != -1) { do { # levats los gilhemets $catalan =~ s/\"//g; print "$catalan\t"; $insertCatalanSth->execute($catalan); $ids[2] = $queryCatalanSth->execute; ($ids[2]) = $queryCatalanSth->fetchrow_array; } if (defined $catalan and length($catalan) > 0); do { # levats los gilhemets $angles =~ s/\"//g; $insertAnglaisSth->execute($angles); $queryAnglaisSth->execute; $ids[3] = $queryAnglaisSth->fetchrow_array; print "$angles\t"; } if (defined $angles and length($angles) > 0); do { # levats los gilhemets $frances =~ s/\"//g; $insertFrancaisSth->execute($frances); $queryFrancaisSth->execute; $ids[3] = $queryFrancaisSth->fetchrow_array; print "$frances\t"; } if (defined $frances and length($frances) > 0); } # if # insertion dans la table des correspondances # toutes les traductions pour le mot occitan for (my $i=1; $i <=3; $i++){ if ($ids[$i] != -1) { $insertTraductionSth->execute($ids[0], $codelangs[0], $ids[$i], $codelangs[$i]); } } # for print "\n"; } # while close FH; #liberation des ressources undef $insertOccitanSth; undef $insertCatalanSth; undef $insertFrancaisSth; undef $insertAnglaisSth; undef $insertTraductionSth; undef $queryOccitanSth; undef $queryCatalanSth; undef $queryFrancaisSth; undef $queryAnglaisSth; $dbh->disconnect; # main sub connecterBaseDonnees{ my $user = 'dca'; my $password = 'coucourou cou cou'; my $db = 'softoccitan'; my $host = 'localhost'; my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host", $user, $password, {RaiseError => 1}); return $dbh; }# connecterBaseDonnees __END__ :endofperl