$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=1;
$rows=$found=0;
for ($i=0 ; $i < $opt_loop_count; $i++)
{
$tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
$dbh->do("insert into $firsttable values ($i,'This is entry $i','')") || die "Got error on insert: $DBI::errstr\n";
$row_count=($i % 7)+1;
$rows+=1+$row_count;
for ($j=0 ; $j < $row_count; $j++)
{
$dbh->do("insert into $secondtable values ($i,$j,0)") || die "Got error on insert: $DBI::errstr\n";
}
}
$dbh->disconnect;
print "Test_1: Inserted $rows rows\n";
exit(0);
}
sub test_delayed_1
{
my ($dbh,$tmpvar,$rows,$found,$i,$id);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=1;
$rows=$found=0;
for ($i=0 ; $i < $opt_loop_count; $i++)
{
$tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
$id=$i+$opt_loop_count;
$dbh->do("insert delayed into $firsttable values ($id,'This is entry $id','')") || die "Got error on insert: $DBI::errstr\n";
$row_count=($i % 7)+1;
$rows+=1+$row_count;
for ($j=0 ; $j < $row_count; $j++)
{
$dbh->do("insert into $secondtable values ($id,$j,0)") || die "Got error on insert: $DBI::errstr\n";
}
if (($tmpvar % 100) == 0)
{
$dbh->do("select max(info) from $firsttable") || die "Got error on select max(info): $DBI::errstr\n";
$dbh->do("select max(value) from $secondtable") || die "Got error on select max(info): $DBI::errstr\n";
$found+=2;
}
}
$dbh->disconnect;
print "Test_1: Inserted delayed $rows rows, found $found rows\n";
exit(0);
}
sub test_delayed_2
{
my ($dbh,$tmpvar,$rows,$found,$i,$id);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=1;
$rows=$found=0;
for ($i=0 ; $i < $opt_loop_count; $i++)
{
$tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
$id=$i+$opt_loop_count*2;
$dbh->do("insert delayed into $firsttable values ($id,'This is entry $id','')") || die "Got error on insert: $DBI::errstr\n";
$row_count=($i % 7)+1;
$rows+=1+$row_count;
for ($j=0 ; $j < $row_count; $j++)
{
$dbh->do("insert delayed into $secondtable values ($id,$j,0)") || die "Got error on insert: $DBI::errstr\n";
}
if (($tmpvar % 100) == 0)
{
$dbh->do("select max(info) from $firsttable") || die "Got error on select max(info): $DBI::errstr\n";
$dbh->do("select max(value) from $secondtable") || die "Got error on select max(info): $DBI::errstr\n";
$found+=2;
}
}
$dbh->disconnect;
print "Test_1: Inserted delayed $rows rows, found $found rows\n";
exit(0);
}
#
# Update records in both tables
#
sub test_2
{
my ($dbh,$id,$tmpvar,$rows,$found,$i,$max_id,$tmp,$sth,$count);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=111111;
$rows=$found=$max_id=$id=0;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$tmp=(($tmpvar + 63) + $i)*3;
$tmp=$tmp-int($tmp/100000)*100000;
$tmpvar^= $tmp;
$tmp=$tmpvar - int($tmpvar/10)*10;
if ($max_id*$tmp == 0)
{
$max_id=0;
$sth=$dbh->prepare("select max(id) from $firsttable where marker=''");
$sth->execute() || die "Got error select max: $DBI::errstr\n";
if ((@row = $sth->fetchrow_array()) && defined($row[0]))
{
$found++;
$max_id=$id=$row[0];
}
}
else
{
$id= $tmpvar % ($max_id-1)+1;
}
if ($id)
{
($count=$dbh->do("update $firsttable set marker='x' where id=$id")) || die "Got error update $firsttable: $DBI::errstr\n";
$rows+=$count;
if ($count > 0)
{
$count=$dbh->do("update $secondtable set value=$i where id=$id") || die "Got error update $firsttable: $DBI::errstr\n";
$rows+=$count;
}
}
}
$dbh->disconnect;
print "Test_2: Found $found rows, Updated $rows rows\n";
exit(0);
}
#
# select records
#
sub test_3
{
my ($dbh,$id,$tmpvar,$rows,$i,$count);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=222222;
$rows=0;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
$id=$tmpvar % $opt_loop_count;
$count=$dbh->do("select id from $firsttable where id=$id") || die "Got error on select from $firsttable: $DBI::errstr\n";
$rows+=$count;
}
$dbh->disconnect;
print "Test_3: Found $rows rows\n";
exit(0);
}
#
# Note that this uses row=1 and in some cases won't find any matching
# records
#
sub test_4
{
my ($dbh,$id,$tmpvar,$rows,$i,$count);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=333333;
$rows=0;
for ($i=0 ; $i < $opt_loop_count; $i++)
{
$tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
$id=$tmpvar % $opt_loop_count;
$count=$dbh->do("select id from $secondtable where id=$id") || die "Got error on select from $secondtable: $DBI::errstr\n";
$rows+=$count;
}
$dbh->disconnect;
print "Test_4: Found $rows rows\n";
exit(0);
}
sub test_5
{
my ($dbh,$id,$tmpvar,$rows,$i,$max_id,$count,$sth);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$tmpvar=444444;
$rows=$max_id=0;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$tmpvar^= ((($tmpvar + 63) + $i)*3 % 100000);
if ($max_id == 0 || ($tmpvar % 10 == 0))
{
$sth=$dbh->prepare("select max(id) from $firsttable");
$sth->execute() || die "Got error select max: $DBI::errstr\n";
if ((@row = $sth->fetchrow_array()) && defined($row[0]))
{
$max_id=$id=$row[0];
}
else
{
$id=0;
}
$sth->finish;
}
else
{
$id= $tmpvar % $max_id;
}
$count=$dbh->do("select value from $firsttable,$secondtable where $firsttable.id=$id and $secondtable.id=$firsttable.id") || die "Got error on select from $secondtable: $DBI::errstr\n";
$rows+=$count;
}
$dbh->disconnect;
print "Test_5: Found $rows rows\n";
exit(0);
}
#
# Delete the smallest row
#
sub test_del
{
my ($dbh,$min_id,$i,$sth,$rows);
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host") || die $DBI::errstr;
$rows=0;
for ($i=0 ; $i < $opt_loop_count/3; $i++)
{
$sth=$dbh->prepare("select min(id) from $firsttable");
$sth->execute() || die "Got error on select from $firsttable: $DBI::errstr\n";
if ((@row = $sth->fetchrow_array()) && defined($row[0]))
{
$min_id=$row[0];
}
$sth->finish;
$dbh->do("delete from $firsttable where id = $min_id") || die "Got error on DELETE from $firsttable: $DBI::errstr\n";