Hi everyone. I'm pretty new to Perl and everything concerned and I have a problem. I have a script that should select some values from a mysql table and copy them to another table (in another db). Then it should update two fields in the first table, so that already copied values aren't copied anymore. But I am not at all able to update them. Plus, are you aware of a way in which I could select data to be copied randomly instead than sequentially?<\br> Here's my code: <\br>
#!/usr/bin/perl #use strict; use diagnostics; ###################################################################### +######################## # si ricercano all'interno del database originario tutti gli alias (r +edirect) di ogni entrata. # Questo file prende in input 3_type_extracted.txt e il database (itwi +ki3) ricercando gli alias # all'interno della tabella redirect. Il file generato è 4_redirect_ty +pe_extracted.txt ###################################################################### +########################## BEGIN { use Exporter (); use vars qw(@ISA @EXPORT @EXPORT_OK); @ISA = qw(Exporter); @EXPORT = qw(); } use vars @EXPORT; use vars @EXPORT_OK; use vars qw(); $|++; use DB_File; use DBI; use Time::HiRes qw( usleep ualarm gettimeofday tv_interval ); use Term::ANSIColor qw(:constants); use Time::ParseDate; use Time::CTime; use HTML::Entities; use HTML::Parse; use Encode qw/is_utf8 decode encode_utf8 _utf8_off/; use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset); use POSIX qw(locale_h); use frameinit; setlocale(LC_ALL, "en_US.iso885915"); $PATHDATA = $frameinit::PATHDATA; $PATHSCRIPTS = $frameinit::PATHSCRIPTS; $debug = 0; $mysqldbpre= $frameinit::MYSQLDBPRE; $mysqldbins=$frameinit::MYSQLDBINS; $mysqldb = $frameinit::MYSQLDB; $mysqluser = $frameinit::MYSQLUSER; $mysqlpwd = $frameinit::MYSQLPWD; $myhost = $frameinit::MYHOST; ############################################# ##Mi collego al primo db ed estraggo i dati## ############################################# $TABLESOURCE = 'ar_web'; $dsn = "DBI:mysql:database=$mysqldbpre;host=$myhost"; $dbh = DBI->connect($dsn, $mysqluser, $mysqlpwd)|| print "NON RIESCO A + CONNETTERMI\n"; my($idc,$query,$dsub); my $range = 40; #Calcolo di un numero random da usare per la selezione dei campi# my $random_number = int(rand($range)); $date = `/bin/date`; $query = "SELECT idc, query, dsub3 FROM $TABLESOURCE where (assigned I +S NULL and evaluated IS NULL and dsub3 not like '') limit 100"; $sth = $dbh->prepare($query); $sth->{"mysql_use_result"} = 1; $sth->execute(); ($idc,$query,$dsub3) = $sth->fetchrow_array or warn "Error in fetch (P +age_id:$page_id): $DBI::errstr\n"; ########################################### ##Aggiorno i dati nella tabella INSTANCE## ########################################### print ">>> crea tabella instance, db $mysqldbins with script in $P +ATHSCRIPTS ... "; $rc = system("cd $PATHSCRIPTS; ./crea_instance.sh"); print "($rc) OK\n"; #print LOG ">>> crea tabella instance, db $mysqldbins => $rc\n"; $TABLEINST = 'instance'; $dsg = "DBI:mysql:database=$mysqldbins;host=$myhost"; $dbk = DBI->connect($dsg, $mysqluser, $mysqlpwd)|| print "NON RIESCO A + CONNETTERMI\n"; while($idc){ $idao = $idc.'_'.$TABLESOURCE; $insert = "insert into $TABLEINST (idao,oggetto,valore) values + (?,?,?)"; $sthy = $dbk->prepare($insert); if(!defined($sthy)){ #print RED,"Error: $DBI::errstr\n$select\n",RESET; } $rvy = $sthy->execute($idao, $query, $dsub3); if(!defined($rvy)){ #print RED,"Error: $DBI::errstr\n$select\n",RESET; } ($idc,$query,$dsub3) = $sth->fetchrow_array } ############################################################## ##Aggiorno i campi Evaluated e Assigned della tabella source## ############################################################## $dsq = "DBI:mysql:database=$mysqldbpre;host=$myhost"; $dbq = DBI->connect($dsq, $mysqluser, $mysqlpwd)|| print "NON RIESCO A + CONNETTERMI\n"; print ">>> update tabella $TABLESOURCE, db $mysqldbpre with script + in $PATHSCRIPTS ... "; while($idc){ $update = "UPDATE $TABLESOURCE SET assigned='1', evaluated='1' + WHERE (idc LIKE '$idc')"; $stq = $dbq->prepare($update); $rvq = $stq->execute($assigned, $evaluated); ($idc,$query,$dsub3) = $sth->fetchrow_array } print "OK\n"; ###################################################################### +########
Thanks to anyone willing to help. Suggestions and criticism are very much appreciated.

In reply to Mysql update table problem by jb22

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.