small fixes : opac lib is the same as librarian lib by default.
[koha.git] / marc / benchmarks / generaterandomdata
1 #!/usr/bin/perl
2 #
3 # This script generates 80,000 random records in the kohabenchmark database for
4 # the purposes of comparing two different marc storage schemas.  It requires
5 # the presence of a word list for populating the data.  Mine is in
6 # /usr/share/dict/words.  Change that if necessary.  You'll also need to change
7 # your userid and password for the dbi->connect line.
8
9 use DBI;
10
11 my $dbh=DBI->connect("dbi:mysql:kohabenchmark", 'youruserid', 'yourpassword');
12 @subfields = ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n');
13
14
15 open (W, "/usr/share/dict/words");
16 while (<W>) {
17     chomp;
18     push @words, $_;
19 }
20
21 my $tagcounter=0;
22 my $subfieldcounter=0;
23 srand($$|time);
24 for ($bibid=1; $bibid<80000; $bibid++) {
25     my $numtags=int(rand(10)+5);
26     my $localtagcounter=0;
27     for ($i=1; $i<$numtags; $i++) {
28         $localtagcounter++;
29         $tagcounter++;
30         my $tag=$i*40+100;
31         my $numsubfields=int(rand(10)+1);
32         my $subfieldsused;
33         my $localsubfieldcounter=0;
34         for ($j=1; $j<=$numsubfields; $j++) {
35             my $code='';
36             until ($code) { 
37                 my $codepicker=int(rand($#subfields));
38                 if ($subfieldsused->{$subfields[$codepicker]}==0) {
39                     $subfieldsused->{$subfields[$codepicker]}=1;
40                     $code=$subfields[$codepicker];
41                 }
42             }
43             $subfieldcounter++;
44             $localsubfieldcounter++;
45             my $word=$words[int(rand($#words))];
46             my $sth=$dbh->prepare("insert into marc_subfield_table (subfieldid, tagid, tag, bibid, subfieldorder, subfieldcode, subfieldvalue) values (?,?,?,?,?,?,?)");
47             my $error=1;
48             while ($error) {
49                 $sth->execute($subfieldcounter, $tagcounter, $tag, $bibid, $localsubfieldcounter, $code, $word);
50                 $error=$dbh->err;
51                 if ($error) {
52                     sleep 1;
53                     print "ERROR: $error\n";
54                 }
55                 $sth->finish;
56             }
57             my $error=1;
58             my $sth=$dbh->prepare("insert into marc_field_table_sergey (bibid, tagid, tag) values (?, ?, ?)");
59             while ($error) {
60                 $sth->execute($bibid, $localtagcounter, $tag);
61                 $error=$dbh->err;
62                 if ($error) {
63                     sleep 1;
64                     print "ERROR: $error\n";
65                 }
66                 $fieldid=$dbh->{'mysql_insertid'};
67                 $sth->finish;
68             }
69             $error=1;
70             $sth=$dbh->prepare("insert into marc_subfield_table_sergey (fieldid, subfieldorder, subfieldcode, subfieldvalue) values (?, ?, ?, ?)");
71             while ($error) {
72                 $sth->execute($fieldid, $localsubfieldcounter, $code, $word);
73                 $error=$dbh->err;
74                 if ($error) {
75                     sleep 1;
76                     print "ERROR: $error\n";
77                 }
78                 $sth->finish;
79             }
80         }
81     }
82 }