63474fc22f
schemas for MARC storage. See IRC log at http://www.haz.cmsd.bc.ca/cgi-bin/kohalog.pl for information on the two proposals.
73 lines
2.1 KiB
Perl
73 lines
2.1 KiB
Perl
#!/usr/bin/perl
|
|
#
|
|
# This script generates 80,000 random records in the kohabenchmark database for
|
|
# the purposes of comparing two different marc storage schemas. It requires
|
|
# the presence of a word list for populating the data. Mine is in
|
|
# /usr/share/dict/words. Change that if necessary. You'll also need to change
|
|
# your userid and password for the dbi->connect line.
|
|
|
|
use DBI;
|
|
|
|
my $dbh=DBI->connect("dbi:mysql:kohabenchmark", 'youruserid', 'yourpassword');
|
|
@subfields = ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n');
|
|
|
|
|
|
open (W, "/usr/share/dict/words");
|
|
while (<W>) {
|
|
chomp;
|
|
push @words, $_;
|
|
}
|
|
|
|
my $tagcounter=0;
|
|
my $subfieldcounter=0;
|
|
srand($$|time);
|
|
for ($bibid=1; $bibid<80000; $bibid++) {
|
|
my $numtags=int(rand(10)+5);
|
|
my $localtagcounter=0;
|
|
for ($i=1; $i<$numtags; $i++) {
|
|
$localtagcounter++;
|
|
$tagcounter++;
|
|
my $tag=$i*40+100;
|
|
my $numsubfields=int(rand(10)+1);
|
|
my $subfieldsused;
|
|
my $localsubfieldcounter=0;
|
|
my $tagvalue='';
|
|
for ($j=1; $j<=$numsubfields; $j++) {
|
|
my $code='';
|
|
until ($code) {
|
|
my $codepicker=int(rand($#subfields));
|
|
if ($subfieldsused->{$subfields[$codepicker]}==0) {
|
|
$subfieldsused->{$subfields[$codepicker]}=1;
|
|
$code=$subfields[$codepicker];
|
|
}
|
|
}
|
|
$subfieldcounter++;
|
|
$localsubfieldcounter++;
|
|
my $word=$words[int(rand($#words))];
|
|
$tagvalue.="\$$code $word\0";
|
|
my $sth=$dbh->prepare("insert into marc_2XX_subfield_table (subfieldid, tagid, tag, bibid, subfieldorder, subfieldcode, subfieldvalue) values (?,?,?,?,?,?,?)");
|
|
my $error=1;
|
|
while ($error) {
|
|
$sth->execute($subfieldcounter, $tagcounter, $tag, $bibid, $localsubfieldcounter, $code, $word);
|
|
$error=$dbh->err;
|
|
if ($error) {
|
|
sleep 1;
|
|
print "ERROR: $error\n";
|
|
}
|
|
$sth->finish;
|
|
}
|
|
}
|
|
$tagvalue=~s/\0$//;
|
|
my $error=1;
|
|
my $sth=$dbh->prepare("insert into marc_0XX_tag_table (bibcode, tagnumber, tagorder, tagvalue) values (?, ?, ?, ?)");
|
|
while ($error) {
|
|
$sth->execute($bibid, $tag, $localtagcounter, $tagvalue);
|
|
$error=$dbh->err;
|
|
if ($error) {
|
|
sleep 1;
|
|
print "ERROR: $error\n";
|
|
}
|
|
$sth->finish;
|
|
}
|
|
}
|
|
}
|