Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
sub insert { my( $table, $data, $key ) = @_; my $t = $key ? "$table-$key" : $table; if( !defined $dbo->{$t} ) { # first time through, set some things up my $db = DBI->connect(DB_IN_SRV, DB_IN_DB, DB_IN_PW, {AutoCommit => AUTOCOMMIT, PrintError => 0}) or die "Couldn't connect to database @{[DB_IN_SRV]} " . DBI->errstr; my $s = [sort keys %$data]; my $sql = "insert into $table(" . join(',' => @$s) . ')values(' . join( ',' => ('?') x @$s ) . ')'; my $ss = $db->prepare($sql) or die "[$table/$t] prepare $sql\n" . $db->errstr . "\n"; @{$dbo->{$t}}{qw/DB STH SQL SORT COUNT ERR/ } = ($db, $sth, $sql, $s, 0, 0); } ++$dbo->{$t}{COUNT}; if( !$dbo->{$t}{STH}->execute( @$data{ @{$dbo->{$t}{SORT}} } ) ) { warn $dbo->{$t}{COUNT}, ': ', $dbo->{$t}{SQL}, "\n", join( "\n", @$data{ @{$dbo->{$t}{SORT}} } ), "\n", $dbo->{$t}{DB}->errstr, "\n\n"; ++$dbo->{$t}{ERR}; # give up quickly if things are going worng if( $dbo->{$t}{COUNT} > 10 and $dbo->{$t}{ERR} > 0.6 * $dbo->{$t}{COUNT} ) { die "Giving up.\n"; } } AUTOCOMMIT or $dbo->{$t}{COUNT} % COMMIT_BATCH or $dbo->{$t}{DB}->commit; }

In reply to Using DBI to transfer data from one database to another by grinder

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (7)
    As of 2014-12-25 17:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (160 votes), past polls