use DBI; use edw; use Benchmark qw(:all) ; my $maximo_connect=$maximoconf{'maximo_connect'}; my $maximo_db_user=$maximoconf{'maximo_db_user'}; my $maximo_pwd=$maximoconf{'maximo_pwd'}; my $edw_connect=$edwconf{'edw_connect'}; my $edw_db_user=$edwconf{'edw_db_user'}; my $edw_pwd=$edwconf{'edw_pwd'}; my $table=$ARGV[0]; my $edw_table="STG_EAM_$ARGV[0]_TB"; my $inserted=0; my $max_commit=30000; my $dbh1 = DBI->connect( $edw_connect, $edw_db_user, $edw_pwd , { Prin +tError => 0, RaiseError => 1,AutoCommit=>0 }); my $dbh = DBI->connect( $maximo_connect, $maximo_db_user, $maximo_pwd +, { PrintError => 0, RaiseError => 1,AutoCommit=>0 }); #$sth = DBI->connect($maximo_connect, $maximo_db_user, $maximo_pwd,{Au +toCommit => 0}) # ->column_info(undef, undef, $table, "%"); $sth=$dbh->column_info(undef, undef, $table, "%"); $sth->execute(); push @fields, $_->{COLUMN_NAME} while $_ = $sth->fetchrow_hashref; my $field_placeholders = join ", ", map {'?'} @fields; my $fieldlist = + join ", ", @fields; my $sth1=$dbh->prepare("SELECT $fieldlist from maximo.$table " ); $sth1->execute(); $t0 = Benchmark->new; my $sql_ins="INSERT INTO $edw_table ( $fieldlist ) VALUES ( $field_placeholders )"; my $sth2=$dbh1->prepare("$sql_ins"); while(@columns=$sth1->fetchrow_array) { $inserted+=$sth2->execute(@columns); unless ($inserted % $max_commit) { $dbh1->do('commit'); $inserted=0; } } $dbh1->do('commit'); $t1 = Benchmark->new; $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n"; $dbh->disconnect(); $dbh1->disconnect(); exit(0);
20101011 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
In reply to DBI Performance help by cool79s
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |