Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and a log crumbles through the grate...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (4)
    As of 2018-04-25 17:35 GMT
    Find Nodes?
      Voting Booth?