made several PKs be auto_increment columns

* biblio.biblionumber
* biblioitems.biblioitemnumber
* items.itemnumber

These IDs are no longer increment by the Perl code, thus
allowing better concurrency during bib/item editing.

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Galen Charlton 2007-11-01 13:38:06 -05:00 committed by Joshua Ferraro
parent af21bbd65a
commit 5fabddfe38
4 changed files with 20 additions and 31 deletions

View file

@ -3460,20 +3460,13 @@ sub _koha_add_biblio {
my $error;
# get the next biblionumber
my $sth = $dbh->prepare("SELECT MAX(biblionumber) FROM biblio");
$sth->execute();
my $data = $sth->fetchrow_arrayref();
my $biblionumber = $$data[0] + 1;
# set the series flag
my $serial = 0;
if ( $biblio->{'seriestitle'} ) { $serial = 1 };
$sth->finish();
my $query =
"INSERT INTO biblio
SET biblionumber = ?,
frameworkcode = ?,
SET frameworkcode = ?,
author = ?,
title = ?,
unititle =?,
@ -3484,9 +3477,8 @@ sub _koha_add_biblio {
datecreated=NOW(),
abstract = ?
";
$sth = $dbh->prepare($query);
my $sth = $dbh->prepare($query);
$sth->execute(
$biblionumber,
$frameworkcode,
$biblio->{'author'},
$biblio->{'title'},
@ -3498,6 +3490,7 @@ sub _koha_add_biblio {
$biblio->{'abstract'}
);
my $biblionumber = $dbh->{'mysql_insertid'};
if ( $dbh->errstr ) {
$error.="ERROR in _koha_add_biblio $query".$dbh->errstr;
warn $error;
@ -3666,16 +3659,10 @@ Internal function to add a biblioitem
sub _koha_add_biblioitem {
my ( $dbh, $biblioitem ) = @_;
my $error;
my $sth = $dbh->prepare("SELECT MAX(biblioitemnumber) FROM biblioitems");
$sth->execute();
my $data = $sth->fetchrow_arrayref;
my $bibitemnum = $$data[0] + 1;
$sth->finish();
my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
my $query =
"INSERT INTO biblioitems SET
biblioitemnumber = ?,
biblionumber = ?,
volume = ?,
number = ?,
@ -3706,9 +3693,8 @@ sub _koha_add_biblioitem {
cn_sort = ?,
totalissues = ?
";
$sth = $dbh->prepare($query);
my $sth = $dbh->prepare($query);
$sth->execute(
$bibitemnum,
$biblioitem->{'biblionumber'},
$biblioitem->{'volume'},
$biblioitem->{'number'},
@ -3739,6 +3725,7 @@ sub _koha_add_biblioitem {
$cn_sort,
$biblioitem->{'totalissues'}
);
my $bibitemnum = $dbh->{'mysql_insertid'};
if ( $dbh->errstr ) {
$error.="ERROR in _koha_add_biblioitem $query".$dbh->errstr;
warn $error;
@ -3761,12 +3748,6 @@ sub _koha_new_items {
my ( $dbh, $item, $barcode ) = @_;
my $error;
my $sth = $dbh->prepare("SELECT MAX(itemnumber) FROM items");
$sth->execute();
my $data = $sth->fetchrow_hashref;
my $itemnumber = $data->{'MAX(itemnumber)'} + 1;
$sth->finish;
my ($items_cn_sort) = GetClassSort($item->{'items.cn_source'}, $item->{'itemcallnumber'}, "");
# if dateaccessioned is provided, use it. Otherwise, set to NOW()
@ -3776,7 +3757,6 @@ sub _koha_new_items {
}
my $query =
"INSERT INTO items SET
itemnumber = ?,
biblionumber = ?,
biblioitemnumber = ?,
barcode = ?,
@ -3806,9 +3786,8 @@ sub _koha_new_items {
materials = ?,
uri = ?
";
$sth = $dbh->prepare($query);
my $sth = $dbh->prepare($query);
$sth->execute(
$itemnumber,
$item->{'biblionumber'},
$item->{'biblioitemnumber'},
$barcode,
@ -3836,6 +3815,7 @@ sub _koha_new_items {
$item->{'materials'},
$item->{'uri'},
);
my $itemnumber = $dbh->{'mysql_insertid'};
if ( defined $sth->errstr ) {
$error.="ERROR in _koha_new_items $query".$sth->errstr;
}

View file

@ -347,7 +347,7 @@ CREATE TABLE `authorised_values` (
DROP TABLE IF EXISTS `biblio`;
CREATE TABLE `biblio` (
`biblionumber` int(11) NOT NULL default 0,
`biblionumber` int(11) NOT NULL auto_increment,
`frameworkcode` varchar(4) NOT NULL default '',
`author` mediumtext,
`title` mediumtext,
@ -380,7 +380,7 @@ CREATE TABLE `biblio_framework` (
DROP TABLE IF EXISTS `biblioitems`;
CREATE TABLE `biblioitems` (
`biblioitemnumber` int(11) NOT NULL default 0,
`biblioitemnumber` int(11) NOT NULL default auto_increment,
`biblionumber` int(11) NOT NULL default 0,
`volume` mediumtext,
`number` mediumtext,
@ -996,7 +996,7 @@ CREATE TABLE `issuingrules` (
DROP TABLE IF EXISTS `items`;
CREATE TABLE `items` (
`itemnumber` int(11) NOT NULL default 0,
`itemnumber` int(11) NOT NULL default auto_increment,
`biblionumber` int(11) NOT NULL default 0,
`biblioitemnumber` int(11) NOT NULL default 0,
`barcode` varchar(20) default NULL,

View file

@ -8,7 +8,7 @@
# and is automatically called by Auth.pm when needed.
sub kohaversion {
return "3.00.00.017";
return "3.00.00.019";
}
1;

View file

@ -525,6 +525,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
SetVersion ($DBversion);
}
$DBversion = "3.00.00.019";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
$dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
$dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
SetVersion ($DBversion);
}
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table