package SQLLoad; use strict; use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(:common); use DBI; use CGI; our $dbh; sub handler { my $r = shift; # Connect to DB $dbh = DBI->connect( "DBI:Oracle:host=oracle.zednax.com;port=1521;sid=XE", "hr", "hr" ) unless $dbh; # Set-up CGI my $cgi = CGI->new($r); my $no_autocommit = $cgi->param('no_autocommit'); if ($no_autocommit) { $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; } my $err = ''; # Do the selects my $select_count = $cgi->param('select_count') || 0; foreach my $i ( 1 .. $select_count ) { my $dbi_query_object = $dbh->prepare("SELECT id FROM zz_system_options WHERE id = 1"); $dbi_query_object->execute(); $err .= "." . $dbh->errstr; } # Do the inserts my $insert_count = $cgi->param('insert_count') || 0; foreach my $i ( 1 .. $insert_count ) { my $dbi_query_object = $dbh->prepare("INSERT INTO zz_system_options (id,option_name) VALUES (zz_system_optionsids.nextval,?)"); $dbi_query_object->execute("load testing"); $err .= "." . $dbi_query_object->errstr; } if ($no_autocommit) { $dbh->commit(); if ($@) { warn "Transaction aborted because $@"; eval { $dbh->rollback }; return Apache2::Const::SERVER_ERROR; } } # Print out some info about this... $r->content_type('text/plain'); $r->print("Errors: $err\n"); return Apache2::Const::OK; } 1;