From 5fabddfe3825411e2f260dea8a4705cea4f02c2c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 1 Nov 2007 13:38:06 -0500 Subject: [PATCH] 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 Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 34 +++++++--------------------------- installer/kohastructure.sql | 6 +++--- kohaversion.pl | 2 +- updater/updatedatabase | 9 +++++++++ 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ab33ee4ca0..810de2f599 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -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; } diff --git a/installer/kohastructure.sql b/installer/kohastructure.sql index 45047b7fa6..d6c7190741 100644 --- a/installer/kohastructure.sql +++ b/installer/kohastructure.sql @@ -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, diff --git a/kohaversion.pl b/kohaversion.pl index 737f24d7c7..0da8e17b75 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -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; diff --git a/updater/updatedatabase b/updater/updatedatabase index 408794e5bc..4b02b1efbf 100755 --- a/updater/updatedatabase +++ b/updater/updatedatabase @@ -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 -- 2.39.5