3
# This is a test with stores big records in a blob.
4
# Note that for the default test the mysql server should have been
5
# started with at least 'mysqld -O max_allowed_packet=30M' and you should have
6
# at least 256M memory in your computer.
12
$opt_user=$opt_password="";
14
$opt_rows=20; # Test of blobs up to ($rows-1)*100000+1 bytes
16
$opt_table="test_big_record";
17
$opt_loop_count=100000; # Change this to make test harder/easier
19
GetOptions("host=s","db=s","user=s", "password=s", "table=s", "rows=i",
20
"compress", "loop-count=i") || die "Aborted";
22
print "Connection to database $test_db\n";
25
$extra_options.=":mysql_compression=1" if ($opt_compress);
27
$dbh = DBI->connect("DBI:mysql:$opt_db:$host$extra_options",$opt_user,$opt_password) || die "Can't connect: $DBI::errstr\n";
29
$dbh->do("drop table if exists $opt_table");
31
print "Creating table $opt_table\n";
34
CREATE TABLE $opt_table (
35
auto int(5) unsigned NOT NULL DEFAULT '0' auto_increment,
37
PRIMARY KEY (auto))")) or die $DBI::errstr;
39
print "Inserting $opt_rows records\n";
41
$|=1; # Flush output to stdout to be able to monitor process
43
for ($i=0 ; $i < $opt_rows ; $i++)
45
$tmp= chr(65+($i % 16)) x ($i*100000+1);
46
$tmp= $dbh->quote($tmp);
47
$dbh->do("insert into $opt_table (test) values ($tmp)") or die $DBI::errstr;
51
print "\nReading records\n";
53
$sth=$dbh->prepare("select * from $opt_table", { "mysql_use_result" => 1}) or die $dbh->errstr;
55
$sth->execute() or die $sth->errstr;
58
while (($row = $sth->fetchrow_arrayref))
60
die "Record $i had wrong data in blob" if ($row->[1] ne (chr(65+($i % 16)) x ($i*100000+1)));
64
die "Didn't get all rows from server" if ($i != $opt_rows);
67
# Test by insert/updating/deleting random rows for a while
70
print "Testing insert/update/delete\n";
73
for ($i= 0 ; $i < $opt_loop_count ; $i++)
75
$length= int(rand 65535);
76
$tmp= chr(65+($i % 16)) x $length;
77
$tmp= $dbh->quote($tmp);
78
$dbh->do("insert into $opt_table (test) values ($tmp)") or die $DBI::errstr;
80
$length=int(rand 65535);
81
$tmp= chr(65+($i % 16)) x $length;
82
$tmp= $dbh->quote($tmp);
83
$id= int(rand $max_row_id);
84
$dbh->do("update $opt_table set test= $tmp where auto= $id") or die $DBI::errstr;
87
$id= int(rand $max_row_id);
88
$dbh->do("delete from $opt_table where auto= $id") or die $DBI::errstr;
90
print "." if ($i % ($opt_loop_count/100) == 1);
93
# $dbh->do("drop table $opt_table") or die $DBI::errstr;