[Koha-bugs] [Bug 10454] Duplicate card numbers may be generated
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Wed Jun 26 19:31:19 CEST 2013
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=10454
--- Comment #13 from Galen Charlton <gmcharlt at gmail.com> ---
Here's a version that shows that one can store multiple sequences in a single
table and add new ones at will:
___BEGIN____
#!/usr/bin/perl
use Modern::Perl;
use C4::Context;
my $dbh = C4::Context->dbh();
### only need to run prep() once
###prep();
$dbh->{AutoCommit} = 0;
my $max = $ARGV[0] || 50;
foreach my $i (0..$max) {
my $val = fetch_next('id1');
print "got $val for sequence 1\n";
next unless 0 == ($i % 3);
$val = fetch_next('id2');
print "got $val for sequence 2\n";
}
sub prep {
$dbh->do('DROP TABLE IF EXISTS sequence');
$dbh->do('CREATE TABLE sequence (id INT NOT NULL, seq varchar(10) NOT NULL)
ENGINE myisam');
$dbh->do('INSERT INTO sequence VALUES (0,"id1")');
$dbh->do('INSERT INTO sequence VALUES (0,"id2")');
}
sub fetch_next {
my $seq = shift;
$dbh->do('UPDATE sequence SET id=LAST_INSERT_ID(id+1) WHERE seq = ?', {},
$seq);
my $sth = $dbh->prepare('SELECT LAST_INSERT_ID()');
$sth->execute();
my @val = $sth->fetchrow_array();
return $val[0];
}
___END___
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list