#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Digest::MD5 qw(md5_hex);

my $db = 'koha;
my $user = 'xxx';
my $padd = 'xxx';
my $count = 5000;
my $borrowerid = 10;
my $branch = 'CPL';
my $biblioid = 92;

my $dbh = DBI->connect("DBI:mysql:$db",$user,$pass);
my $sth;

die "failed to connect to MySQL database:DBI->errstr()" unless($dbh);

sub create {

    my $req_sql = "INSERT INTO illrequests (borrowernumber, branchcode, biblio_id, status, backend) VALUES (borrowerid, $branch, $biblioid, 'NEW', 'FreeForm')";

    $sth = $dbh->prepare($req_sql)
        or die "prepare statement failed: $dbh->errstr()";
    $sth->execute() or die "execution failed: $dbh->errstr()";

    my $id = $sth->{mysql_insertid};

    my $attr = {
        title => md5_hex(time),
        author => md5_hex(time + 1)
    };

    foreach my $key(keys %{$attr}) {
        $dbh->do("INSERT INTO illrequestattributes (illrequest_id, type, value) VALUES ($id, '$key', '" . $attr->{$key} . "')");
    }
}

foreach my $i(0..$count) {
    print "$i\n";
    &create();
}

$sth->finish();
$dbh->disconnect();