http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=10454
--- Comment #13 from Galen Charlton <[email protected]> --- 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. _______________________________________________ Koha-bugs mailing list [email protected] http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
