big_record.pl
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:1k
- #!/usr/bin/perl
- # This is a test with stores big records in a blob
- # Note that for the default test the mysql server should have been
- # started with at least 'mysqld -O max_allowed_packet=200k'
- $host= shift || "";
- $test_db="test";
- $opt_user=$opt_password="";
- use DBI;
- $|= 1; # Autoflush
- $table="test_big_record";
- $rows=20; # Test of blobs up to ($rows-1)*10000+1 bytes
- print "Connection to database $test_dbn";
- $dbh = DBI->connect("DBI:mysql:$test_db:$host",$opt_user,$opt_password) || die "Can't connect: $DBI::errstrn";
- $dbh->do("drop table if exists $table");
- print "Creating table $tablen";
- ($dbh->do("
- CREATE TABLE $table (
- auto int(5) unsigned NOT NULL DEFAULT '0' auto_increment,
- test mediumblob,
- PRIMARY KEY (auto))")) or die $DBI::errstr;
- print "Inserting $rows recordsn";
- for ($i=0 ; $i < $rows ; $i++)
- {
- $tmp= chr(65+$i) x ($i*10000+1);
- $tmp= $dbh->quote($tmp);
- $dbh->do("insert into $table (test) values ($tmp)") or die $DBI::errstr;
- }
- print "Testing recordsn";
- $sth=$dbh->prepare("select * from $table") or die $dbh->errstr;
- $sth->execute() or die $sth->errstr;
- $i=0;
- while (($row = $sth->fetchrow_arrayref))
- {
- print $row->[0]," ",length($row->[1]),"n";
- die "Record $i had wrong data in blob" if ($row->[1] ne (chr(65+$i)) x ($i*10000+1));
- $i++;
- }
- die "Didn't get all rows from server" if ($i != $rows);
- $dbh->do("drop table $table") or die $DBI::errstr;
- print "Test okn";
- exit 0;